我想让脚本搜索 $open_email_msg ,不同的电子邮件将有不同的信息,但格式相同,如下所示。
我并没有真正使用正则表达式太多,但我想做的是每当我用它来搜索字符串时,它都会搜索“标题:[标题数据]”,“类别:[类别数据]。我问因为我不认为类似的事情
strpos($open_email_msg, "Title: (*^)");
甚至会起作用。
这只是整个代码的一个片段,其余部分将信息插入 MySQL 表中,然后发布到网站上的新闻文章中。
有人可以帮我找到解决方案吗?
严格的电子邮件格式:
新闻动态
标题:文章标题
标签: 标签1 标签2
类别:文章类别、第二文章类别
片段:
文章片段。
消息:文章消息。图片。更多文字,更多文字。 Lorem ipsum dolor 坐 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
?>