How PHP handles method code samples with Chinese URLs

Source: Internet
Author: User
This article mainly introduces the PHP processing with Chinese URL method, involving PHP code conversion related operation skills, with a certain reference value, the need for friends can refer to the next

The example in this article describes how PHP handles a Chinese URL. Share to everyone for your reference, as follows:

IE6 hyperlinks there will be problems when there is Chinese, the evil IE6 ah. PHP makes the built-in UrlEncode function also does not, urlencode the backslash and other ASCII character also to encode, still can not solve the problem, use the following function can solve this problem.

The simple principle is to convert all byte with byte greater than 127 to 16 binary.

Hyperlink address in Chinese

UTF-8 encoded with the ' Http://ftp.php.cn/PHP video tutorial. rar ';//urlencode result: Echo UrlEncode ($url); http%3a%2f%2fftp1.zdy.co% 2fmovie%2f%e6%88%91%e4%b8%ba%e7%9b%b8%e4%ba%b2%e7%8b%82.rmvb//link_urldecode results: Echo link_urldecode ($url); http:/ /ftp1.zdy.co/movie/%e6%88%91%e4%b8%ba%e7%9b%b8%e4%ba%b2%e7%8b%82.rmvb//link_urldecode functions: Function Link_urldecode ($url) {  $uri = ';  $cs = Unpack (' c* ', $url);  $len = count ($cs);  for ($i =1; $i <= $len; $i + +) {    $uri. = $cs [$i] > 127? '% '. Strtoupper (Dechex ($cs [$i)): $url {$i-1};  }  return $uri;}

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.