PHP parsing the URL function with Chinese characters share, _php tutorial

Source: Internet
Author: User

The URL function for parsing the in-band characters in PHP is shared,


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.
Copy the Code code 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.com true http://www.bkjia.com/PHPjc/945717.html techarticle PHP in the parsing of the URL function with Chinese characters to share, many times, when writing Web applications, will encounter Chinese and other character conflicts, for example, some URL links contain Chinese ...

  • 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.