URL function sharing _php techniques in PHP parsing with Chinese characters

Source: Internet
Author: User

Many times, when writing a Web application, you will encounter Chinese and other character conflicts, such as some URL link contains the characters, then in the use of wget/curl/file_get_contents and so on to get information will directly hit a big "404", will be very silent.

Here is a small function to solve this problem, but only in the path to parse it, the relevant functions involved in the use of people can view the manual on the line.

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

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.