This article mainly introduced in PHP parsing with Chinese characters in the URL function sharing, this article directly gives the implementation code, the focus is on the use of Rawurlencode function, the need for friends can refer to the
Many times, when writing a Web application, you will encounter Chinese and other character conflicts, such as some URL link contains the characters, then in the use of wget/curl/file_get_contents and so on to get information will directly hit a big "404", will be very silent.
Here is a small function to solve this problem, but only in the path to parse it, the relevant functions involved in the use of people can view the manual on the line.
The code is as follows:
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;
}