I’ve created this regex
(www|http://)[^ ]+
that match every http://… or www…. but I dont know how to make preg_replace that would work, I’ve tried
preg_replace('/((www|http://)[^ ]+)/', '<a href="\1">\1</a>', $str);
but it doesn’t work, the result is empty string.
You need to escape the slashes in the regex because you are using slashes as the delimiter. You could also use another symbol as the delimiter.