在 PHP 中搜索字符串标题后的数据
我正在尝试让脚本搜索 $open_email_msg ,不同的电子邮件将具有不同的信息,但格式相同,如下所示。我只想要他们在标题:或标签:或类别之后放置的任何内容:无论要捕获的数据,而不是字符串“标题:”或“标签:”或“类别:”这只是整个代码的一个片段,其余的将信息插入 MySQL 表中,然后发布到网站上的新闻文章中。
有人可以帮我找到解决方案吗?
严格的电子邮件格式:
新闻更新
标题:文章标题
标签: 标签1 标签2
类别:文章类别、第二文章类别
片段:文章片段。
信息: 文章留言。图片。更多文字,更多文字。 Lorem impsum dolor sat 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"
$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
?>
I am trying to get the scripts to search the $open_email_msg which different e-mails will have different info but the same format as below. I just want whatever they put after Title: or Tags: or Categories: whatever that data is to be captured and not the string "Title:" or "Tags:" or "Categories:" This is just a snippet of the whole code, the rest inserts the info into a MySQL table and then is posted to a News Article on the site.
Can somebody help me find a solution to this please?
Strict e-mail message format:
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"
$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
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
试试这个:
Try this: