caballero Posted September 3, 2010 Share Posted September 3, 2010 Howdy, I'm in trouble here. Does someone know how to wrap a url which is in the string with href tag without writing like a few hundred line long code? Example: Before: "This is a url http://www.domain.com and then some text" After: "This is a url <a href="http://www.domain.com">http://www.domain.com</a> and then some text" the string is to be received by a flash application right after. Link to comment https://forums.phpfreaks.com/topic/212460-how-to-wrap-a-url-which-is-in-the-string-with-href-tag/ Share on other sites More sharing options...
freelance84 Posted September 3, 2010 Share Posted September 3, 2010 $url = "www.url.com"; $href_url="<a href=\"http://$url\">http://$url</a> Link to comment https://forums.phpfreaks.com/topic/212460-how-to-wrap-a-url-which-is-in-the-string-with-href-tag/#findComment-1106951 Share on other sites More sharing options...
ldb358 Posted September 3, 2010 Share Posted September 3, 2010 <?php function replace_links($string){ $start = strpos($string, 'http://'); if($start !== false){ $end = strpos($string, " ",$start); $link = substr($string, $start,$end-$start); $link = "<a href='$link'>".$link."</a>"; return substr_replace($string,$link,$start,$end-$start); }else{ return $string; } } ?> Link to comment https://forums.phpfreaks.com/topic/212460-how-to-wrap-a-url-which-is-in-the-string-with-href-tag/#findComment-1106953 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.