Page 1 of 1

Replace string within string with certain characters

Posted: Tue Dec 22, 2009 11:06 am
by BriceHulse
Is there a way to put an anchor href tag around every word in $str with the characters "http://" or "https://"?

Re: Replace string within string with certain characters

Posted: Tue Dec 22, 2009 1:02 pm
by MichaelR

Code: Select all

$newstring = preg_replace('#\b(https?://\S*)\b#i', '<a href="$1">$1</a>', $str);