php – 在strpos()的字符串中使用正则表达式

我想要获取脚本来搜索$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];

这应该给你字符串的初始位置.

请注意,我正在使用的正则表达式可能是错误的,不考虑行尾和东西,但这是另一个主题.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


如何选择合适的 C++ Web 开发框架?
利用 C++ 框架构建高并发 Web 应用的策略
用 C++ 框架开发跨平台图形应用程序
golang框架中安全编码实践的最佳指南是什么?
golang框架与其他语言框架在设计理念上的区别有哪些?
C++ 图形框架与其他语言框架的比较
C++ 框架与其他 Web 开发框架的对比分析
使用 C++ 框架构建大型项目最佳实践
C++ 框架如何提高大型项目开发效率
C++ 框架中依赖注入的持续集成与部署工具
如何与社区协作和贡献到自定义 Golang 框架?
C++ 框架在大型项目中如何实现模块化开发
使用 C++ 框架开发跨平台 Web 应用
C++ 框架在大型项目中的优缺点
golang框架在性能上的优势体现在哪些方面?
C++ 框架在嵌入式系统内存优化中的优势
golang框架在人工智能与机器学习中的作用
如何扩展 Golang 框架以支持特定功能?
如何利用 Go Modules 和依赖项管理来自定义 Golang 框架?
Golang 框架中的性能优化技巧