Home > Backend Development > PHP Tutorial > json返回值带函数名,PHP里如何回调呢

json返回值带函数名,PHP里如何回调呢

WBOY
Release: 2016-06-13 12:06:04
Original
1228 people have browsed it

json返回值带函数名,PHP里怎么回调呢?

本帖最后由 zlbpolly 于 2014-08-26 21:22:37 编辑 以下内容是抓取到的,现在我只能截取字符串,把函数名过滤掉,再按json格式取值。
有没有办法直接回调函数呢?
<br />jsonp3({ "status": 200, "ercode": 0});<br />
Copy after login

------解决方案--------------------
没有好办法,因为 php 尚不支持把对象写作 {}
不知道你是怎样把函数名过滤掉的
php5.4及以下可写作
$s  = 'jsonp3({ "status": 200, "ercode": 0})';<br />preg_replace('/^\w+?\((.+)\)$/ise', 'count($r=json_decode("$1"))', $s);<br />print_r($r);<br />
Copy after login
php5.3及以上可写作
$s  = 'jsonp3({ "status": 200, "ercode": 0})';<br />preg_replace_callback('/^\w+?\((.+)\)$/is', function($m) use (&$r) { $r = json_decode($m[1]); }, $s);<br />print_r($r);<br />
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template