This article mainly introduces the sharing of the url function with Chinese characters in PHP. This article directly gives the implementation code, focusing on the use of the rawurlencode function. Friends in need can refer to it
Many times , when writing web applications, you will encounter problems with conflicts between Chinese and other characters. For example, some URL links contain Chinese characters, so when you use wget/curl/file_get_contents, etc. to obtain information, you will directly Hitting a big "404" will make you speechless.
A small function is written here to solve this problem. It is only limited to parsing in the path. You can check the manual for the related functions involved.
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; }
The above is the detailed content of Detailed explanation of the example of parsing url function with Chinese characters in PHP. For more information, please follow other related articles on the PHP Chinese website!