我需要帮助删除包含PHP中的超链接的单词。示例:
I was here dumb*
*有超链接
我希望它是这样的:
I was here
没有dumb
有人可以帮我这个吗? 感谢。
修改:
我要加载“This page”,然后删除包含超链接的所有字词。例如:“LYSSNA,BILD SVENSKA / BILD FINSKA”
答案 0 :(得分:3)
function findAndReplace($arr) {
return '<strong>'.$arr[1].'</strong>';
}
$inputText = 'Why use <a href="#" style="padding-left:5px"> PHP </a>?';
echo "<br />Input is: <br />";
echo $inputText;
$returnText = preg_replace_callback('@<a(?:.*)>(.*)</a>@isU', 'findAndReplace', $inputText);
echo "<br /><br />Output will be: <br />";
echo $returnText;
来源:http://php-opensource-help.blogspot.com/2010/10/how-to-remove-hyperlink-from-string.html
修改强>
您编辑原始帖子后: 试试:
$new_string=preg_replace ("/<a.*>/i","",$string);
答案 1 :(得分:2)
我认为这应该有效:
$string_without_hyperlinks = preg_replace('/<a\s.*?>.*?<\/a>/s', '', $string);