I need some help with removing words that contains hyperlinks in PHP. Example:
I was here dumb*
*has hyperlink
I want it to be like this:
I was here
without dumb
Can someone help me on this? Thanks.
Edit:
I am gonna load "This page" and then remove all words containing hyperlinks. Example: "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;
Source: http://php-opensource-help.blogspot.com/2010/10/how-to-remove-hyperlink-from-string.html
EDIT
Since you edited your original post: Try:
$new_string=preg_replace ("/<a.*>/i","",$string);
I think this should work:
$string_without_hyperlinks = preg_replace('/<a\s.*?>.*?<\/a>/s', '', $string);