gpt4 book ai didi

php - 正则表达式排除标题标签之间的内容

转载 作者:行者123 更新时间:2023-12-04 00:40:06 25 4
gpt4 key购买 nike

这个排除标题标签内容的正则表达式有什么问题?

$plaintext = preg_match('#<title>(.*?)</title>#', $html);

$html有整个页面的html代码。

最佳答案

听起来您从来没有得到有效的答案。让我们删除标题标签。

搜索:(?s)<title>.*?</title>

替换:""

代码:

$regex = "~(?s)<title>.*?</title>~";
$ replaced = preg_replace($regex,"",$pagecontent);

解释正则表达式

(?s)                     # set flags for this block (with . matching
# \n) (case-sensitive) (with ^ and $
# matching normally) (matching whitespace
# and # normally)
<title> # '<title>'
.*? # any character (0 or more times (matching
# the least amount possible))
</title> # '</title>'

关于php - 正则表达式排除标题标签之间的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19818570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com