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 Link to comment https://forums.phpfreaks.com/topic/104661-php-regular-expression/ 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); Link to comment https://forums.phpfreaks.com/topic/104661-php-regular-expression/#findComment-535733 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>'); ?> Link to comment https://forums.phpfreaks.com/topic/104661-php-regular-expression/#findComment-535969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.