How php resolves Chinese characters in URLs

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.