Welcome to Dream.In.Code
Getting Help is Easy!

Join 131,793 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,597 people online right now. Registration is fast and FREE... Join Now!




Convert Input Text (url address) into clickable links

 
Reply to this topicStart new topic

Convert Input Text (url address) into clickable links

devonator
post 9 Oct, 2008 - 12:09 PM
Post #1


New D.I.C Head

*
Joined: 6 Sep, 2008
Posts: 43


My Contributions


I want to create a html widget that can convert text url (paste ins) into clickable links...
I have done the layout in html, heres my codes below. It has a input text field and a buttons...
how can i take the input text and select them line by line and turn them into clickable html? I'v read the the xml tutorials on w3school it wasn't very helpful...

eg. if i paste in:
http://sdvsdv.com/
http://sdvsdv.com/

in the text field i get on the next page:
the clickble links:
1. http://sdvsdv.com/
2. http://sdvsdv.com/

thanks for the help in advance


CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Link Converter</title>
</head>
<body>
<center>
<body bgcolor="white">
<font color="black">
<b>paste links below:</b>
</font>
<br></br>
<textarea rows="25" cols="70"></textarea>
</br></br>
<form action="">
<input type="button" value="convert">
<input type="button" value="quite">
</form>
</center>
</body>
</html>


This post has been edited by devonator: 9 Oct, 2008 - 12:11 PM
User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 9 Oct, 2008 - 01:11 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,008



Thanked 171 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Well this can't be done just with HTML and CSS. You will need a server-side programming language which will read the form entries and parse it looking for URLs and replacing them with full HTML URLs <a> tags. So if you had something like PHP then you would read in the specified field from the $_POST or $_GET array, then with something like a regular expression you would find pattern matches (like using preg_match_all()) which you then would replace using something like preg_replace which you would then replace with the proper <a> html tags.

Below is an example I use for a contact us app that replaces http://, https:// and www urls with clickable <a> tag equivalents...

CODE

// Creates URL links for URLs that start with http://, https://, or "www"
function addDisplayURLLinks($contactContent = "") {
    
        $contactContent = preg_replace("/(http[s]?:\/\/)([a-zA-Z0-9_\\\\.\/]*\.)+[a-zA-Z]{2,6}/i","<a href=\"$0\">$0</a>",$contactContent);
        $contactContent = preg_replace_callback("/\swww\.([a-zA-Z0-9_\\\\.\/]*\.)+[a-zA-Z]{2,6}/i",create_function('$matches','$theurl = "http://" . trim($matches[0]); return "<a href=\"$theurl\">$theurl</a>";'),$contactContent);
        return $contactContent;
}


Of course this isn't perfect in all situations but it gets most of the decently formatted URLs out there. Feel free to use as your own leisure.

Hope it helps. smile.gif
User is offlineProfile CardPM

Go to the top of the page

devonator
post 9 Oct, 2008 - 11:08 PM
Post #3


New D.I.C Head

*
Joined: 6 Sep, 2008
Posts: 43


My Contributions


thanks very much
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 04:44PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month