The following format is generally used when jsonp output in php:
callbackname('json string');
If the middle json string contains single quotes, there is a problem with this output, and the caller generally cannot handle it, so we need to escape the single quotes.
If it is generated using json_encode, it can be escaped in the following way:
<span>$ret</span> = json_encode(<span>$result</span>,<span> JSON_HEX_APOS); </span><span>header</span>('Content-Type: text/javascript; charset=utf-8'<span>); </span><span>echo</span> <span>$callback</span> . '(\'' . <span>$ret</span> . '\');';
Here JSON_HEX_APOS is provided by php and replace the single quotes with u0027.
If it is string concatenation, you can use the following method:
<span>$jsonData</span> = <span>preg_replace</span>('/\'/', '\u0027', <span>$jsonData</span>);
Then output.