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 Quote Link to comment 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); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.