I have the following variable:
$text = 'This is a sentence [url=http://site.com] that contains urls [url=javascript:alert();]';
and the following line of code to validate URLs:
$text = preg_replace('/\[url=([^\\]]+)]/', filter_var('$1', FILTER_VALIDATE_URL), $text);
Output:
“This is a sentence that contains urls”
How can I get the following as output?
“This is a sentence http://site.com that contains urls”
1 Answer