[英]How to remove words with hyperlinks from a string in PHP?
我需要一些幫助來刪除PHP中包含超鏈接的單詞。 例:
I was here dumb*
*具有超鏈接
我希望它是這樣的:
I was here
沒有dumb
有人可以幫我嗎? 謝謝。
編輯 :
我將加載“ 此頁面 ”,然后刪除所有包含超鏈接的單詞。 示例:“ LYSSNA,BILD SVENSKA / BILD FINSKA”
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);
我認為這應該工作:
$string_without_hyperlinks = preg_replace('/<a\\s.*?>.*?<\\/a>/s', '', $string);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.