Home > Backend Development > PHP Tutorial > Share the function of parsing url with Chinese characters in PHP, _PHP tutorial

Share the function of parsing url with Chinese characters in PHP, _PHP tutorial

WBOY
Release: 2016-07-13 10:09:21
Original
931 people have browsed it

Sharing the function of parsing url with Chinese characters in php,

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, which will directly conflict when using wget/curl/file_get_contents, etc. to obtain information. A big "404" will be very 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.

Copy code 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;                                              }






http://www.bkjia.com/PHPjc/945717.html
www.bkjia.comtrue

http: //www.bkjia.com/PHPjc/945717.htmlTechArticleSharing the url function with Chinese characters in php. Many times, when writing web applications, you will encounter The problem of conflict between Chinese and other characters, for example, some URL links contain Chinese...
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