blufish Posted August 9, 2008 Share Posted August 9, 2008 I want to know how to if I wrote http://www.frozenoven.com to convert it into <a href="http://www.frozenoven.com" rel="nofollow">http://www.frozenoven.com</a> Probably simple for you genuises! Blufish Link to comment https://forums.phpfreaks.com/topic/118899-solved-question-about-url-detection/ Share on other sites More sharing options...
ratcateme Posted August 9, 2008 Share Posted August 9, 2008 $url = "http://www.frozenoven.com"; $url = "<a href=\"{$url}\" rel=\"nofollow\">{$url}</a> Scott. Link to comment https://forums.phpfreaks.com/topic/118899-solved-question-about-url-detection/#findComment-612255 Share on other sites More sharing options...
blufish Posted August 9, 2008 Author Share Posted August 9, 2008 what if the it's like hey guys check out this site at http://www.frozenoven.com Link to comment https://forums.phpfreaks.com/topic/118899-solved-question-about-url-detection/#findComment-612256 Share on other sites More sharing options...
ratcateme Posted August 9, 2008 Share Posted August 9, 2008 i wrote a similar script a while back here is a modified version <?php function link_url($url) { $url_href = substr($url, 0, 7) != "http://" ? "http://{$url}" : $url; return "<a href=\"{$url_href}\" rel=\"nofollow\">{$url}</a>"; } echo "<pre>"; $string = "hey guys check out this site at http://www.frozenoven.com http://www.test.com www.dsa.com www.asd.com"; //for http:// $count = substr_count($string, "http://"); $start = 0; $len = 0; for ($i = 1; $i <= $count; $i++) { $start = strpos($string, "http://", $start + $len + 27); $len = strpos($string . " ", " ", $start) - $start; $url = substr($string, $start, $len); $string = str_replace(" " . $url, " " . link_url($url), $string, $asd); } //for www $count = substr_count($string, " www."); $start = 0; $len = 0; for ($i = 1; $i <= $count; $i++) { $start = strpos($string, " www.", $start + $len) + 1; $len = strpos($string . " ", " ", $start) - $start; $url = substr($string, $start, $len); $string = str_replace(" " . $url, " " . link_url($url), $string, $asd); } var_dump($string); ?> Scott. Link to comment https://forums.phpfreaks.com/topic/118899-solved-question-about-url-detection/#findComment-612265 Share on other sites More sharing options...
papaface Posted August 9, 2008 Share Posted August 9, 2008 what if the it's like hey guys check out this site at http://www.frozenoven.com i wrote a similar script a while back here is a modified version <?php function link_url($url) { $url_href = substr($url, 0, 7) != "http://" ? "http://{$url}" : $url; return "<a href=\"{$url_href}\" rel=\"nofollow\">{$url}</a>"; } echo "<pre>"; $string = "hey guys check out this site at http://www.frozenoven.com http://www.test.com www.dsa.com www.asd.com"; //for http:// $count = substr_count($string, "http://"); $start = 0; $len = 0; for ($i = 1; $i <= $count; $i++) { $start = strpos($string, "http://", $start + $len + 27); $len = strpos($string . " ", " ", $start) - $start; $url = substr($string, $start, $len); $string = str_replace(" " . $url, " " . link_url($url), $string, $asd); } //for www $count = substr_count($string, " www."); $start = 0; $len = 0; for ($i = 1; $i <= $count; $i++) { $start = strpos($string, " www.", $start + $len) + 1; $len = strpos($string . " ", " ", $start) - $start; $url = substr($string, $start, $len); $string = str_replace(" " . $url, " " . link_url($url), $string, $asd); } var_dump($string); ?> Scott. Or you could just do: <?php $subject = "hey guys check out this site at http://www.frozenoven.com"; preg_match('/\\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i', $subject,$matches); echo $matches[0]; ?> Will echo http://www.frozenoven.co Link to comment https://forums.phpfreaks.com/topic/118899-solved-question-about-url-detection/#findComment-612316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.