Phpjsonp single quotes escape, jsonp quotes escape _ PHP Tutorial

Source: Internet
Author: User
Phpjsonp single quotes and jsonp single quotes. Phpjsonp single quotation mark escape: callbackname (jsonstring) is generally used in php jsonp output. if the jsonstring in the middle contains single quotation marks, this output will be escaped by php jsonp single quotation marks, jsonp quotation mark escape

The following format is generally used for jsonp output in php:

Callbackname ('json string ');

If the json string in the middle contains single quotation marks, this output is problematic and the caller cannot handle it. Therefore, we need to escape single quotation marks.

If json_encode is used to generate an object, you can use the following method to escape the object:

$ Ret = json_encode ($ result, JSON_HEX_APOS); header ('content-Type: text/javascript; charset = utf-8 '); echo $ callback. '(\''. $ ret. '\');';

Here, JSON_HEX_APOS is provided by php to replace the single quotation mark with \ u0027.

For string concatenation, you can use the following method:

$ JsonData = preg_replace ('/\'/',' \ u0027 ', $ jsonData );

And then output.

Http://www.bkjia.com/PHPjc/916030.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/916030.htmlTechArticlephp jsonp single quotes escape, jsonp quotes escape jsonp output in php is generally in the following format: callbackname ('json string'); if the json string in the middle contains single quotes, this output is...

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.