这样的字符串如何解析
程序员文章站
2022-04-03 17:05:35
...
这样的字符串怎么解析
下边是文件中一行字符串:
[2007-08-01 00:00:00] 218.200.244.69 - - "GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS&dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!1257454712!1185897536315&MISC_ServiceID=30070881&MISC_AccessMode=2&MISC_MID=00110080331963 HTTP/1.0 " 200 8376 "- " "TSD-TP005 " wap.chinam.com 1
我想取如下数据,大家帮忙看看应该怎么解析:
[2007-08-01 00:00:00]
218.200.244.69
-
-
"GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS&dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!1257454712!1185897536315&MISC_ServiceID=30070881&MISC_AccessMode=2&MISC_MID=00110080331963 HTTP/1.0 "
200
8376
-
"TSD-TP005 "
wap.chinam.com
1
------解决方案--------------------
$html = "[2007-08-01 00:00:00] 218.200.244.69 - - \ "
GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS
&dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!
1257454712!1185897536315&MISC_ServiceID=30070881&MISC_AccessMode=2&MISC_MID=00110080331963
HTTP/1.0\ " 200 8376 \ "-\ " \ "TSD-TP005\ " wap.chinam.com 1 ";
$match = '/\[([^]]*)\]([^ "]*)\ "([^ "]*)\ "/is ';
$re = preg_match_all (
$match,
$html,
$out);
print_r( $out );
echo $re;
?>
后面的照写就成
------解决方案--------------------
参考:
===============================
$str = '[2007-08-01 00:00:00] 218.200.244.69 - - "GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS&dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!1257454712!1185897536315&MISC_ServiceID=30070881&MISC_AccessMode=2&MISC_MID=00110080331963 HTTP/1.0 " 200 8376 "- " "TSD-TP005 " wap.chinam.com 1 ';
$arr = preg_match_all( '/(\ "(.[^\ "]*?)\ ")|(\[(.[^\]]*?)\])|(\s(.[^\s+]*?)\s)|(.[^\s]*)/ ',$str,$m);
print_r($m[0]);
------解决方案--------------------
$s = [2007-08-01 00:00:00] 218.200.244.69 - - "GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS&
dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!1257454712!1185897536315&MISC_ServiceID=3007
0881&MISC_AccessMode=2&MISC_MID=00110080331963 HTTP/1.0 " 200 8376 "- " "TSD-TP005 " wap.chinam.com 1
H;
$r = preg_split( "/\s+/ ",$s);
print_r($r);
下边是文件中一行字符串:
[2007-08-01 00:00:00] 218.200.244.69 - - "GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS&dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!1257454712!1185897536315&MISC_ServiceID=30070881&MISC_AccessMode=2&MISC_MID=00110080331963 HTTP/1.0 " 200 8376 "- " "TSD-TP005 " wap.chinam.com 1
我想取如下数据,大家帮忙看看应该怎么解析:
[2007-08-01 00:00:00]
218.200.244.69
-
-
"GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS&dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!1257454712!1185897536315&MISC_ServiceID=30070881&MISC_AccessMode=2&MISC_MID=00110080331963 HTTP/1.0 "
200
8376
-
"TSD-TP005 "
wap.chinam.com
1
------解决方案--------------------
$html = "[2007-08-01 00:00:00] 218.200.244.69 - - \ "
GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS
&dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!
1257454712!1185897536315&MISC_ServiceID=30070881&MISC_AccessMode=2&MISC_MID=00110080331963
HTTP/1.0\ " 200 8376 \ "-\ " \ "TSD-TP005\ " wap.chinam.com 1 ";
$match = '/\[([^]]*)\]([^ "]*)\ "([^ "]*)\ "/is ';
$re = preg_match_all (
$match,
$html,
$out);
print_r( $out );
echo $re;
?>
后面的照写就成
------解决方案--------------------
参考:
===============================
$str = '[2007-08-01 00:00:00] 218.200.244.69 - - "GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS&dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!1257454712!1185897536315&MISC_ServiceID=30070881&MISC_AccessMode=2&MISC_MID=00110080331963 HTTP/1.0 " 200 8376 "- " "TSD-TP005 " wap.chinam.com 1 ';
$arr = preg_match_all( '/(\ "(.[^\ "]*?)\ ")|(\[(.[^\]]*?)\])|(\s(.[^\s+]*?)\s)|(.[^\s]*)/ ',$str,$m);
print_r($m[0]);
------解决方案--------------------
$s = [2007-08-01 00:00:00] 218.200.244.69 - - "GET /cmcc/ani/klfyt_detail_at.jsp?nofee=1&type=video&id=10477&sid=GUIBWqU0F57trFtS&
dirid=0428100540&p=1&session=&MISC_ID=999&MISC_SessionID=999-df1b2815!1434701435!1257454712!1185897536315&MISC_ServiceID=3007
0881&MISC_AccessMode=2&MISC_MID=00110080331963 HTTP/1.0 " 200 8376 "- " "TSD-TP005 " wap.chinam.com 1
H;
$r = preg_split( "/\s+/ ",$s);
print_r($r);
相关文章
相关视频
上一篇: php 字符串如何转换为数组
下一篇: php如何隐藏图片
推荐阅读
-
解析如何用SQL语句在指定字段前面插入新的字段
-
SpringBoot 源码解析 (七)----- Spring Boot的核心能力 - SpringBoot如何实现SpringMvc的?
-
jsonobject解析json字符串特别慢(json格式转换文本的方法)
-
java解析xml字符串如何解析(解析xml字符串的方式)
-
php一个解析字符串排列数组的方法
-
如何在python字符串中输入纯粹的{}
-
如何推广产品?第一步要解析商品的概念
-
内容平台管理难题如何破?知乎的答案是这样的
-
详细解析平面设计师如何选择优秀的设计素材
-
Mybaits 源码解析 (十二)----- Mybatis的事务如何被Spring管理?Mybatis和Spring事务中用的Connection是同一个吗?