This article mainly introduces the sharing of url functions with Chinese characters in php. This article provides the implementation code directly, focusing on the use of rawurlencode functions. For more information, see, when writing a webpage application, you may encounter conflicts between Chinese characters and other characters. for example, some url links contain Chinese characters, when wget/curl/file_get_contents is used to obtain information, it will directly hit a large "404", which will be speechless.
Here we have written a small function to solve this problem, but it is limited to parsing in the path. you can check the manual for the related function usage.
The code is as follows:
Function urlConvert ($ url ){
$ PathArr = array ();
$ Modules = parse_url ($ url );
$ Path = $ modules ['path'];
$ Patheatmap = explode ('/', $ path );
Foreach ($ patheatmap as $ row ){
$ PathArr [] = rawurlencode ($ row );
}
$ UrlNew = $ modules ['scheme ']. ": //". $ modules ['host']. implode ('/', $ pathArr );
Return $ urlNew;
}