Solved

URL in Database not a Hyperlink

Posted on 2013-10-25
1
390 Views
Last Modified: 2013-10-25
I have an input form where user can insert any kind of text.  It's then stored in the database.  If they user posts a link it's stored as text.  The page that the link is then displayed on is also just text.  

How do I automatically have it show as a hyperlink the user can then click?  

It's on a .php page using php and mysqli.
0
Comment
Question by:N R
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39601736
<?php
function toAnchorLink($text) {
	return preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text);
}

echo toAnchorLink("some text http://www.google.com more text");

Open in new window

0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question