本帖最后由 lzh68575536 于 2020-11-28 15:12 编辑
[Asm] 纯文本查看 复制代码 $str = '{"time":"2020-11-27 09:41:01","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 09:41:43","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 09:44:16","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}
{"time":"2020-11-27 10:03:01","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":"null=1"}
{"time":"2020-11-27 10:03:29","ip":"192.168.0.1","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/86.0.4240.198 Safari\/537.36 Edg\/86.0.622.69","url":"http:\/\/damn.com\/","query":""}';
$str1=explode("\n",$str);
$data = [];
foreach($str1 as $value){
$val = json_decode($value,true);
$data[] = [
'time'=>$val['time'],
'ip'=>$val['ip'],
'user_agent'=>$val['user_agent'],
'url'=>$val['url'],
'query'=>$val['query'],
];
}
echo '<pre>';
var_dump($data);
echo '</pre>';
显示结果:
array(5) {
[0]=>
array(5) {
["time"]=>
string(19) "2020-11-27 09:41:01"
["ip"]=>
string(11) "192.168.0.1"
["user_agent"]=>
string(131) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69"
["url"]=>
string(16) "http://damn.com/"
["query"]=>
string(0) ""
}
[1]=>
array(5) {
["time"]=>
string(19) "2020-11-27 09:41:43"
["ip"]=>
string(11) "192.168.0.1"
["user_agent"]=>
string(131) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69"
["url"]=>
string(16) "http://damn.com/"
["query"]=>
string(0) ""
}
[2]=>
array(5) {
["time"]=>
string(19) "2020-11-27 09:44:16"
["ip"]=>
string(11) "192.168.0.1"
["user_agent"]=>
string(131) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69"
["url"]=>
string(16) "http://damn.com/"
["query"]=>
string(0) ""
}
[3]=>
array(5) {
["time"]=>
string(19) "2020-11-27 10:03:01"
["ip"]=>
string(11) "192.168.0.1"
["user_agent"]=>
string(131) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69"
["url"]=>
string(16) "http://damn.com/"
["query"]=>
string(6) "null=1"
}
[4]=>
array(5) {
["time"]=>
string(19) "2020-11-27 10:03:29"
["ip"]=>
string(11) "192.168.0.1"
["user_agent"]=>
string(131) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36 Edg/86.0.622.69"
["url"]=>
string(16) "http://damn.com/"
["query"]=>
string(0) ""
}
} |