Solved

URL in Database not a Hyperlink

Posted on 2013-10-25
1
385 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
<? versus <?php 5 36
RDBMS and No sql database 4 42
Session timeout 5 13
How to loop bootstrap columns which contain database records 9 19
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now