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里面,求高人指导 展开
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里面,求高人指导 展开
1个回答
展开全部
我写了个事例,应该是你想要的。
<?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;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询