无法通过 preg_match_all 获得所需结果
我正在尝试编写一个电子邮件管道 php 脚本,该脚本将通过电子邮件获取传入流量更新报告,并提取其中的相关信息以存储到数据库中。
电子邮件通常以一些介绍开始,重要信息以以下格式显示。
Highway : Some Highway
Time : 08-Oct-2010 08:10 AM
Condition : Smooth (or slow moving etc)
我尝试使用此代码
preg_match_all('/(?P<\name>\w+) : (?P<\data>\w+)/i', $subject, $result);
请注意< / 确实只是<但不知何故,它们没有显示在这里。
匹配只是:
Highway : Some
Datetime : 08
Condition : Smooth
任何人都可以告诉我第二个正则表达式中缺少什么吗?为什么它不包含“:”之后的整个字符串?
I am trying to program a email piping php script that would take an incoming traffic update report via email, and extract the relevant information within it to store into a database.
The email usually starts with some introduction, with the important information displayed in the following format.
Highway : Some Highway
Time : 08-Oct-2010 08:10 AM
Condition : Smooth (or slow moving etc)
I tried with this code
preg_match_all('/(?P<\name>\w+) : (?P<\data>\w+)/i', $subject, $result);
Note the < / are really just < but somehow they are not being displayed here.
And the matches are only:
Highway : Some
Datetime : 08
Condition : Smooth
Can anybody tell me what's missing in my second regex expression? Why doesn't it include the entire string of words after the ":"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在捕获
\w+
。只匹配单词字符,不包括空格或括号。尝试
使用
.*?
这将匹配新行字符之前的所有内容You are capturing
\w+
. That only matches word characters, this does not include spaces or parenthesis.Try
try using
.*?
This will match everything up to the new line character