There are times when you might encounter a URL with Chinese. This article mainly describes how PHP parses the Chinese characters in the URL, using the Rawurlencode function and using the instance code to understand how PHP resolves Chinese characters in the URL.
Many times, when writing a Web application, you will encounter Chinese and other character conflicts, such as the URL link contains the text character, then the use of wget/curl/file_get_contents and so on to get information when it will directly hit a big "404", will be very silent.
Here is a small function to solve this problem, just limited in path to parse it, related to the function of the use of people can view the manual on the line.
function Urlconvert ($url) { $PATHARR = array (); $modules = Parse_url ($url); $path = $modules [' path ']; $pathSplit = explode ('/', $path); foreach ($pathSplit as $row) { $PATHARR [] = Rawurlencode ($row); } $urlNew = $modules [' scheme ']. ":/ /". $modules [' Host '].implode ('/', $PATHARR); return $urlNew; }
Related recommendations:
Search engine friendly hidden index.php_php tutorial by Path_info Way
PHP http request Urlencode/rawurlencode
An in-depth analysis of PHP Rawurlencode and UrlEncode functions _php tutorials