php jsonp单引号转义,jsonp引号转义
Jun 13, 2016 am 09:20 AM
jsonpphpDownapostrophequotation markshourescapeoutput
php jsonp单引号转义,jsonp引号转义
php中jsonp输出时一般用下面的格式:
callbackname('json string');
如果中间的json string中含有单引号,这个输出就是有问题的,调用方一般是无法处理的,所以我们要对单引号进行转义。
如果是用json_encode方式生成可以用下面的方式转义:
<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> . '\');';
这里 JSON_HEX_APOS 是php是提供的把单引号换为 \u0027 了。
如果是字符串拼接的,可以用下面的方式:
<span>$jsonData</span> = <span>preg_replace</span>('/\'/', '\u0027', <span>$jsonData</span>);
然后再输出。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks agoByDDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft