我想要获取脚本来搜索$open_email_msg哪些不同的电子邮件将有不同的信息,但格式如下.
我没有真正使用正则表达式,但我想要做的是每当我搜索要搜索的字符串“标题:[数据的标题]”,“类别:[类别的数据]我问因为我不认为像
strpos($open_email_msg,"Title: (*^)");
甚至会工作.
这只是整个代码的片断,其余的将信息插入到MysqL表中,然后发布到网站上的新闻文章.
有人可以帮我找到一个解决方案吗?
严格电子邮件格式:
News Update
Title: Article Title
Tags: tag1 tag2
Categories: Article Category,2nd Article Category
Snippet:
Article snippet.
Message: Article Message. Images. More text,
more text. Lorem impsum dolor sit amet.<?PHP //These functions searches the open e-mail for the the prefix defining strings. //Need a function to search after the space after the strings because the subject,categories,snippet,tags and message are constant-changing. $subject = strpos($open_email_msg,"Title:"); //Searches the open e-mail for the string "Title" $subject = str_replace("Title: ","",$subject); $categories = strpos($open_email_msg,"Categories:"); //Searches the open e-mail for the string "Categories" $snippet = strpos($open_email_msg,"Snippet"); //Searches the open e-mail for the string "Snippet" $content = strpos($open_email_msg,"Message"); //Searches the open-email for the string "Message" $tags = str_replace(' ',',$subject); //DDIE $uri = str_replace(' ','-',$subject); //DDIE $when = strtotime("now"); //date article was posted ?>
尝试使用PREG_OFFSET_CAPTURE标志为
preg_match
.这样的事情:
preg_match('/Title: .*/',$open_email_msg,$matches,PREG_OFFSET_CAPTURE); echo $matches[0][1];
这应该给你字符串的初始位置.
请注意,我正在使用的正则表达式可能是错误的,不考虑行尾和东西,但这是另一个主题. 原文链接:https://www.f2er.com/php/139686.html