我有这个字符串:
$body = '<a href="/title/tt2034800/?ref_=inth_ov_tt"> The Great Wall</a>';
我想删除:
?ref_=inth_ov_tt
来自 $body 。
我测试了这段代码,但没有工作:
$body = preg_replace('#ref_=(.*?)"#is', '', $body);
最佳答案
将您的正则表达式模式更改为以下内容:
$body = '<a href="/title/tt2034800/?ref_=inth_ov_tt"> The Great Wall</a>';
$body = preg_replace('#\?ref_=([^"]+)(?=")#i', '', $body);
print_r($body);
输出(作为源代码):
<a href="/title/tt2034800/"> The Great Wall</a>
关于php - 如何从PHP中的字符串中删除文本到文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42326438/