mmsolutions Posted November 24, 2009 Share Posted November 24, 2009 This is a bit of a niche really. What I want is when you type the following URL ( http://www.google.co.uk ) and it gets saved into the mysql database. Next step is when this is echoed onto the website I want this to be displayed as <a href="http://www.google.co.uk">http://www.google.co.uk</a> so that users can click on the link as a live hyperlink. This is often acheived on most blogs and it must be relatively simple. Many thanks Link to comment https://forums.phpfreaks.com/topic/182769-website-url-conversion/ Share on other sites More sharing options...
thebadbad Posted November 24, 2009 Share Posted November 24, 2009 If the database field simply contains the URL, it's just as simple as <?php //variable $url retrieved from database call echo "<a href=\"$url\">$url</a>"; ?> If you want 'inline' URLs to be converted, e.g. in a body text, you can use a fairly simple regular expression: <?php $text = 'Inline URLs like http://google.com/ found in this string will be converted to HTML links.'; echo preg_replace('~\bhttps?://\S+~i', '<a href="$0">$0</a>', $text); ?> Link to comment https://forums.phpfreaks.com/topic/182769-website-url-conversion/#findComment-964660 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.