欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP提取Json当中的几个数据!50分求解答 高手来帮忙下!

程序员文章站 2022-03-16 11:39:33
...
网址例如:http://123456.com/Ashx/actForm.ashx?action=addorder&gameid=65&num=10&realname=小梦&UserEmail=xiaomeng@qq.com&SearchPass=123654
提交以后的显示是 {"types":"OK","msg":"17961_14102404200616788"}
我想用PHP直接调用出 _ 以后的数字 14102404200616788
不知道怎么实现,本人新手,不太懂 百度了半天!


回复讨论(解决方案)

$s = '{"types":"OK","msg":"17961_14102404200616788"}';
echo explode('_', json_decode($s)->msg)[1];

$s = '{"types":"OK","msg":"17961_14102404200616788"}';
echo explode('_', json_decode($s)->msg)[1];


简洁,但是不能直接在后面加[1]

//$result = file_get_contents('http://123456.com/Ashx/actForm.ashx?action=addorder&gameid=65&num=10&realname=小梦&UserEmail=xiaomeng@qq.com&SearchPass=123654');$result = '{"types":"OK","msg":"17961_14102404200616788"}';$json = json_decode($result,true);$id = explode('_',$json['msg']);echo $id[1];

{"types":"OK","msg":"17961_14102404200616788"} 但是 他每次这个 生成 都不一样哇 !!!

例如
{"types":"OK","msg":"17961_14102404200616788"}
{"types":"OK","msg":"17962_14102453453453453"}
{"types":"OK","msg":"17963_14102534534534535"}
{"types":"OK","msg":"17964_14102534534534534"}
打开一次 他生成一次哇!

每次不一样有什么问题呢,处理方法都一样。

 $result = array(     '{"types":"OK","msg":"17961_14102404200616788"}',     '{"types":"OK","msg":"17962_14102453453453453"}',     '{"types":"OK","msg":"17963_14102534534534535"}',     '{"types":"OK","msg":"17964_14102534534534534"}' );foreach($result as $v){    echo getdata($v).'
';}function getdata($str){ $data = json_decode($str, true); list($id, $timestamp) = explode('_', $data['msg']); return $timestamp;}


14102404200616788
14102453453453453
14102534534534535
14102534534534534

现在调用出来了 接下来 要怎么把 14102404200616788 Json 调用到 JS那边去 例如别人网站 显示

在线页面
正在跳转页面... ...