PHP Jsonp single quote escape

Source: Internet
Author: User

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, json_hex_apos); 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.

PHP Jsonp single quote escape

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.