Reputation: 13853
I need a way of taking a string that contains <a href="url">something</a>
and remove it completely from the string.
So,
$text = 'Something string <a href="url">something</a> some more string';
Any ideas?
Upvotes: 0
Views: 379
Reputation: 1344
I don't understand you question perfectly, but you can use these PHP functions to replace the string:
str_replace();
or
preg_replace();
Upvotes: 0
Reputation: 9300
Removing an anchor is as simple as using this function
echo strip_tags($text)
In case you would want to allow the tag, just add it as a parameter.
Upvotes: 3
Reputation: 31518
$text = str_replace('<a href="url">something</a>', '', $text);
And, if there's a little more variables, preg_replace()
:
$text = preg_replace('/<a href="[^"]+">.+?</a>/i', '', $text);
However, there are several risks and shortcomings when combining HTML and regex.
Upvotes: 1