Lior Lior - 4 months ago 8
PHP Question

Remove urls using PHP

I'd like to only remove the anchor tags and the actual urls.

For instance,

<a href="http://www.example.com">test www.example.com</a>
would become
test
.

Thanks.

Answer

To complement gd1's answer, this will get all the URLs:

// http(s)://
$txt = preg_replace('|https?://www\.[a-z\.0-9]+|i', '', $txt);
// only www.
$txt = preg_replace('|www\.[a-z\.0-9]+|i', '', $txt);