JSHINER Posted July 31, 2007 Share Posted July 31, 2007 <?php $content = "This is the content with a link: http://www.link.com - visit the site!" echo $content; ?> How can I make it so if someone enters a link it makes the address is clickable? And if they only enter www, it includes http:// in the href. Link to comment https://forums.phpfreaks.com/topic/62668-solved-making-a-clickable-link-from-a-variable/ Share on other sites More sharing options...
wildteen88 Posted July 31, 2007 Share Posted July 31, 2007 You will want to use regular expressions using preg_replace. Have a search through the Regex Help forum. I'm pretty sure there has been question like yours already posted within that board. Link to comment https://forums.phpfreaks.com/topic/62668-solved-making-a-clickable-link-from-a-variable/#findComment-311898 Share on other sites More sharing options...
mrjcfreak Posted July 31, 2007 Share Posted July 31, 2007 A quick glance at the php.net manual reveals this: <?php function hyperlink(&$text) { // match protocol://address/path/ $text = ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*", "<a href=\"\\0\">\\0</a>", $text); // match www.something $text = ereg_replace("(^| |.)(www([.]?[a-zA-Z0-9_/-])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text); } ?> Source: http://uk2.php.net/manual/en/function.ereg-replace.php#75448 Link to comment https://forums.phpfreaks.com/topic/62668-solved-making-a-clickable-link-from-a-variable/#findComment-311899 Share on other sites More sharing options...
JSHINER Posted July 31, 2007 Author Share Posted July 31, 2007 Searched, found the solution. Thanks! Link to comment https://forums.phpfreaks.com/topic/62668-solved-making-a-clickable-link-from-a-variable/#findComment-311908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.