JavaScript-How to eliminate the differences between PHP and JS on URL codec, unified pre-and post-end URL encoding and decoding

Source: Internet
Author: User
Both PHP and JS have different ways of handling some special characters for URL encoding and decoding. It's not considered here. escape(), mainly JS's encodeURI() 、encodeURIComponent()With PHP's urlencode() 、rawurlencode()

Access to the information is:
urlencode()The _-. characters are processed, and the spaces are encoded differently from the other functions;
urlencode()rawurlencode() ~ It's not the same as the right deal.
encodeURI()does not encode except _-. the outside~!*()'
encodeURIComponnect()does not encode except _-. the outside~!@#$&*()=:/,;?+'

Assuming that the encoding of the UTF-8, how to unify the front and back end of the URL codec? What better solution to deal with this problem

Reply content:

Both PHP and JS have different ways of handling some special characters for URL encoding and decoding. This is not considered escape() , mainly JS and encodeURI() 、encodeURIComponent() PHPurlencode() 、rawurlencode()

Access to the information is:
urlencode()The _-. characters are processed, and the spaces are encoded differently from the other functions;
urlencode()rawurlencode() ~ It's not the same as the right deal.
encodeURI()does not encode except _-. the outside~!*()'
encodeURIComponnect()does not encode except _-. the outside~!@#$&*()=:/,;?+'

Assuming that the encoding of the UTF-8, how to unify the front and back end of the URL codec? What better solution to deal with this problem

Transcoding is used to escape special characters in the URL, with Encodeuricomponnect has been no problem

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