如何打印包含 preg_match 中的单词的行?
mysql 表“server_var_dump”中的字段包含许多详细信息,包括站点访问者的 USER_AGENT。现在我只需要包含行的 USER_AGENTs 。现在我编写了以下脚本来匹配输出字符串的 USER_AGENT。 现在我只需要打印包含 USER_AGENT 的行
$result = mysql_query("SELECT server_var_dump FROM pageviews LIMIT 0,10");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
//printf("%s", $row["server_var_dump"]);
if(preg_match("/[USER_AGENT]/", $row["server_var_dump"])){
echo "match found.";
}
else
echo "No matches found";
}
请建议我如何打印包含 USER_AGENT 的行?
谢谢!
A field in mysql table "server_var_dump" which contains many details including USER_AGENT of the visitors of site. Now I only need USER_AGENTs containing line. Now I have written following script to match the USER_AGENT of the output string.
Now I need to print only those lines which contains the USER_AGENT
$result = mysql_query("SELECT server_var_dump FROM pageviews LIMIT 0,10");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
//printf("%s", $row["server_var_dump"]);
if(preg_match("/[USER_AGENT]/", $row["server_var_dump"])){
echo "match found.";
}
else
echo "No matches found";
}
Please suggest me how do I print the line which contains USER_AGENT?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一旦得到行就打印它有什么问题吗?
或者,您需要像这样获取匹配的值:
What's wrong with just printing the row once you got it?
Alternatively, you'll need to get the matched values like so:
例子:
Example:
o/p 的 ok 部分是这样的: http://pastebin.com/e1qHG64Q
当我给
它时,它给我像数组数组数组数组一样的o/p
当按照建议给出 strstr 时,它会给出类似数组的 o/p ( 数组 ( 数组 (
。用 /n 爆炸 o/p 可能不起作用..我可以做任何其他黑客来从中获取 USER_AGENT 行吗?
ok part of o/p is something like this: http://pastebin.com/e1qHG64Q
when I give
it gives me o/p like array array array array
and when the strstr is given as suggested it gives o/p like array ( array ( array (
. exploding the o/p with /n is probably not working.. any other kinda hack I can do to get just the USER_AGENT line from it?
成功了! ;)
got the hack! ;)