php用$str = preg_replace('/\s/', '#', $str);里面正则表达式怎么写?

txt文件内容如下:null([{"kjgplist":[{"id":973412,"haoma":"01,10,07,09,05","haomaArray":["01"... txt文件内容如下:

null([ {"kjgplist":[{"id":973412,"haoma":"01,10,07,09,05","haomaArray":["01","10","07","09","05"],"chonghao":0,"pubdate":{"nanos":0,"time":1440864000000,"minutes":0,"seconds":0,"hours":0,"month":7,"year":115,"timezoneOffset":-480,"day":0,"date":30},"lianhao":0,"typeid":8,"zjjine":"","qihao":"15083052","zhushu":"","xiaoliang":""},{"id":973406,"haoma":"09,08,01,03,07","haomaArray":["09","08","01","03","07"],"chonghao":0,"pubdate":{"nanos":0,"time":1440864000000,"minutes":0,"seconds":0,"hours":0,"month":7,"year":115,"timezoneOffset":-480,"day":0,"date":30},"lianhao":0,"typeid":8,"zjjine":"","qihao":"15083051","zhushu":"","xiaoliang":""},{"id":973400,"haoma":"02,08,10,04,09","haomaArray":["02","08","10","04","09"],"chonghao":0,"pubdate":{"nanos":0,"time":1440864000000,"minutes":0,"seconds":0,"hours":0,"month":7,"year":115,"timezoneOffset":-480,"day":0,"date":30},"lianhao":0,"typeid":8,"zjjine":"","qihao":"15083050","zhushu":"","xiaoliang":""},{"id":973394,"haoma":"11,07,10,04,08","haomaArray":["11","07","10","04","08"],"chonghao":0,"pubdate":这后面还有很多。省略了。
代码这么写
error_reporting( E_ALL&~E_NOTICE );
$str = file_get_contents('1.txt');
$str = preg_replace('/\s/', '#', $str);
$arr = explode('#', $str);
print_r($arr); //xianshi arr neirong
这行$str = preg_replace('/\s/', '#', $str);的正则表达应该怎么写?我只需要采集第一行的01,10,07,09,05和第四行的15083052 ,用('/\s/'不能把相应的数据放到arr里面,求高人指导
展开
 我来答
dispose
推荐于2016-06-13 · TA获得超过642个赞
知道小有建树答主
回答量:458
采纳率:0%
帮助的人:494万
展开全部
我写了个事例,应该是你想要的。

<?php
$str = 'null([ {"kjgplist":[{"id":973412,"haoma":"01,10,07,09,05","haomaArray":["01","10","07","09","05"],"chonghao":0,"pubdate":{"nanos":0,"time":1440864000000,"minutes":0,"seconds":0,"hours":0,"month":7,"year":115,"timezoneOffset":-480,"day":0,"date":30},"lianhao":0,"typeid":8,"zjjine":"","qihao":"15083052","zhushu":"","xiaoliang":""},{"id":973406,"haoma":"09,08,01,03,07","haomaArray":["09","08","01","03","07"],"chonghao":0,"pubdate":{"nanos":0,"time":1440864000000,"minutes":0,"seconds":0,"hours":0,"month":7,"year":115,"timezoneOffset":-480,"day":0,"date":30},"lianhao":0,"typeid":8,"zjjine":"","qihao":"15083051","zhushu":"","xiaoliang":""},{"id":973400,"haoma":"02,08,10,04,09","haomaArray":["02","08","10","04","09"],"chonghao":0,"pubdate":{"nanos":0,"time":1440864000000,"minutes":0,"seconds":0,"hours":0,"month":7,"year":115,"timezoneOffset":-480,"day":0,"date":30},"lianhao":0,"typeid":8,"zjjine":"","qihao":"15083050","zhushu":"","xiaoliang":""},';

preg_match_all('/,"haoma":"([0-9,]+)",/is', $str,  $matched);
$haoma = $matched[1];

preg_match_all('/,"qihao":"([0-9]+)",/is', $str,  $matched);
$qihao = $matched[1];

echo "<pre>";
print_r($haoma);
print_r($qihao);
echo "</pre>";
exit;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式