如何从 php 中的字符串中删除文本到文本?
How to remove text to text from string in php?
我有这个字符串:
$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>
我有这个字符串:
$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>