Replace string within string with certain characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BriceHulse
Forum Newbie
Posts: 2
Joined: Tue Dec 22, 2009 11:03 am

Replace string within string with certain characters

Post by BriceHulse »

Is there a way to put an anchor href tag around every word in $str with the characters "http://" or "https://"?
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: Replace string within string with certain characters

Post by MichaelR »

Code: Select all

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