A brief discussion of PHP source code twenty-three: About the urlencode function

不言
Release: 2023-04-02 06:04:01
Original
2786 people have browsed it

This article mainly introduces the twenty-three about the PHP source code: About the urlencode function, it has certain reference value. Now I share it with you. Friends in need can refer to it.

The PHP source code is briefly discussed. Twenty-three: Regarding the urlencode function

I haven’t read the source code of PHP for a while. Recently I have been reading the books I bought before. Some of the books have been read once, but a year later there are different things. Feeling

The urlencode function is often encountered during the development process. It acts on string encoding and uses it for the request part of the URL.
The urlencode function is used to encode the URL string
string urlencode (string str)
Returns a string. All non-alphanumeric characters in this string except -_. will be replaced with a percent sign (%) followed by two hexadecimal digits, and spaces will be Encoded as a plus sign ( ). This encoding is the same as the encoding of WWW form POST data, and the same encoding as the application/x-www-form-urlencoded media type. For historical reasons, this encoding differs from the RFC1738 encoding (see rawurlencode()) in encoding spaces as plus signs ( ).
In line 493 of the standard/url.c file, you can see the implementation of this function

 out_str = php_url_encode(in_str, in_str_len, &out_str_len);RETURN_STRINGL(out_str, out_str_len, 0);
Copy after login

When looking at the php_url_encode function, I struggled for a long time because it has a #ifndef CHARSET_EBCDIC compilation Judgment, I have always regarded #ifndef as #ifdef, which makes it weird to understand

php_url_encode function is a process of traversing the entire string and replacing each character,
For except - All non-alphanumeric characters except _. will be replaced with a percent sign (%) followed by two hexadecimal digits,
There is processing for EBCDIC encoding at compile time

Spaces are encoded as plus signs ( ) (
if (c == ' ') {
*to = ' ';
}

The above is the entire content of this article, I hope it will be helpful to everyone Learning will be helpful. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

A brief discussion of PHP source code 21: About the array_slice function

A brief discussion on PHP source code twenty-two: About the array_splice function

The above is the detailed content of A brief discussion of PHP source code twenty-three: About the urlencode function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!