cheatasp Posted May 8, 2008 Share Posted May 8, 2008 Dear All, I have some problem I have string like that "www.something.com" How can i replace it to "<a href=www.something.com>www.something.com</a>" Thanks Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted May 8, 2008 Share Posted May 8, 2008 not sure if this is what u want.... $str = "www.something.com"; $new = preg_replace("/($str)/", "<a href=$1>$1[/url]", $str); Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 8, 2008 Share Posted May 8, 2008 I am assuming there is more text in the string than just a URL, other wise preg_replace is useless, anyways give this a try: <?php $str = 'Hello this is my url www.mysite.com check it out!'; echo $new = preg_replace('~(www\..*|http://.*)\s~','<a href="$1">$1</a>'); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.