gpt4 book ai didi

PHP 正则表达式 : Replace substring between two special character

转载 作者:搜寻专家 更新时间:2023-10-31 20:43:27 25 4
gpt4 key购买 nike

更新问题:

$li_text = $li->plaintext;
echo '<br>'.$li_text;
echo '<br>'.$li_text = preg_replace('/\:(.*?)\>/',':', $li_text);

$li 获取值 "Qualification : School & Graduation > BE/B.Tech ( Engineering ) "//通过使用来自其他网站的简单 html DOM 解析/p>

我得到的输出是

Qualification : School & Graduation > BE / B.Tech ( Engineering )
Qualification : School & Graduation > BE / B.Tech ( Engineering )

如果我分配 $li_text = "Qualification : School & Graduation > BE/B.Tech (Engineering)" 那么 REGEX 工作正常。

最佳答案

您的代码运行良好。请注意,preg_replace 不会更改主题(即 $str),但会返回一个结果。

preg_replace() returns an array if the subject parameter is an array, or a string otherwise.

If matches are found, the new subject will be returned, otherwise subject will be returned unchanged or NULL if an error occurred.

所以:

preg_replace('/:(.*?)\>/',':', $str);

echo $str;

错误。但是:

$str = preg_replace('/:(.*?)\>/',':', $str);

echo $str;

正在工作

关于PHP 正则表达式 : Replace substring between two special character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16897121/

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