I am attempting to change a string occurance e.g. http://www.bbc.co.uk/ so that it appears inside a html link e.g. <a href="http://www.bbc.co.uk/">http://www.bbc.co.uk</a>
however for some reason my regex conversion does not work. Can someone please point me in the correct direction?
$text = "I love this website http://www.bbc.co.uk/";
$x = preg_replace("#[a-z]+://[^<>\s]+[[a-z0-9]/]#i", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $text);
var_dump($x);
outputs I love this website http://www.bbc.co.uk/ (No html link)
Your weird character class is at fault:
Double square brackets are for POSIX character classes like
[[:digit:]].You meant to write just: