PHP Jsonp single quote escape

Source: Internet
Author: User
PHP single and double quotation marks can modify the string type of data, if the decorated string contains variables (example $name), the biggest difference is: Double quotation marks will replace the value of the variable, and the single quotation marks it as a string output.

PHP JSONP output is generally in the following format:

Callbackname (' JSON string ');

If the middle JSON string contains single quotes, this output is problematic and the caller is generally unable to handle it, so we want to escape the single quotes.

If it is generated in Json_encode mode, it can be escaped in the following way:

$ret = Json_encode ($result,header(' Content-type:text/javascript; charset= Utf-8 'echo$callback$ret . '\');';

Here Json_hex_apos is PHP is provided to the single quote to \u0027.

If it is a string concatenation, you can use the following method:

$jsonData Preg_replace $jsonData);

and then output.

The above describes the PHP jsonp single-quote escape, including the Jsonp single-quote escape, I hope the PHP tutorial interested in a friend helpful.

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