: This article mainly introduces the single quotes escape of phpjsonp. For more information about PHP tutorials, see. PHP single quotes and double quotes can modify string data. if the modified string contains a variable (for example, $ name), the biggest difference is that double quotes replace the variable value, the single quotation mark will output it as a string.
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.
The preceding section describes the single-byte escape of php jsonp, including the single-byte escape of jsonp. if you are interested in the PHP Tutorial.