How To Make Clickable Text URL Links From Text Links Change To Clicking

RegisterLogin
How To Make Clickable Text URL Links From Text Links Change To Clicking
Post Description: How To Make Clickable Text URL Links From Text Links Change To Clicking
Tags: How, To, Make, Clickable, Text, URL, Links, From, Text, Links, Change, To, Clicking
This Post Was Posted On Feb 29, 2008 By webmaster #1210
today i will teach you how to make clickable links from ordinary text.
for example, lets say someone wrote this article in your site like your blog, forums or guestbook.

--------- start of article

Hi everyone, i am writing this short article to show you how you can make ordinary text into clickable link. In my example, i will make www.wallpaperama.com and/or http://www.wallpaperama.com into links that people can click to when they post topics, articles, posts, blogs etc..

--------- end of article

ok, in my above example, i have two urls i can make into clickable links:

1. www.wallpaperama.com
2. http://www.wallpaperama.com

so after you have applied the this functions below, the example article will have two link and it should look like this:

--------- start of article with clickable links

Hi everyone, i am writing this short article to show you how you can make ordinary text into clickable link. In my example, i will make www.wallpaperama.com and/or http://www.wallpaperama.com into links that people can click to when they post topics, articles, posts, blogs etc..

--------- end of article with clickable links

for this PHP script to work, you must have PHP hosting, if you don't have PHP hosting on your website, you can contact our friends at www.webune.com to sign up with one of their PHP plans.

now to make it work. the first step is to copy and paste the following code into your text editor, you can use notepad in windows if you like.


     Code:
<?

function clickable_link($text)
{
# this functions deserves credit to the fine folks at phpbb.com

$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\1:", $text);

// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;

// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, comma, double quote or <
$ret = preg_replace("#(^|[n ])([w]+?://[w#$%&~/.-;:=,?@[]+]*)#is", "\1<a href="\2" target="_blank">\2</a>", $ret);

// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
// zzzz is optional.. will contain everything up to the first space, newline,
// comma, double quote or <.
$ret = preg_replace("#(^|[n ])((www|ftp).[w#$%&~/.-;:=,?@[]+]*)#is", "\1<a href="http://\2" target="_blank">\2</a>", $ret);

// matches an email@domain type address at the start of a line, or after a space.
// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
$ret = preg_replace("#(^|[n ])([a-z0-9&-_.]+?)@([w-]+.([w-.]+.)*[w]+)#i", "\1<a href="mailto:\2@\3">\2@\3</a>", $ret);

// Remove our padding..
$ret = substr($ret, 1);
return $ret;
}
$text="www.wallpaperama.com";

?>
<HTML>
<TITLE>Making Text URLs Into Clicable Links Tutorial</TITLE>
<HEAD>
<style type="text/css">
<!--
.style2 {color: #0066FF}
-->
</style>
</HEAD>
<BODY>
<h1 align="center" class="style2">Making Text URLs Into Clicable Links Tutorial</h1>
<p>the clickable link is before function is: <strong><?php echo $text; ?></strong></p>
<p>this is the text after the <span class="style2">clickable_link_function</span>: <?php echo clickable_link($text); ?> </p>
<hr size="2" noshade>
<p> If you have benefited or learned from this short &quot;Howto&quot; tutorial, we would appreciate if you can provide a link to our http://www.wallpaperama.com. By linking to Wallpaperama, you will make these tutorials more available to others who are looking for information like this.</p>
<p>Thank You</p>
<p>Wallpaperama Team</p>
<p><a href="http://www.wallpaperama.com/forums">&lt;&lt; Go Back</a> </p>
<p align="center">PHP Hosting by <a href="http://www.webune.com">Webune.com</a> </p>
<p>
</BODY>
</HTML>


now save this file as clickable-link.php and upload to your website, then open it with your browser and it will show you it works. you can also look at the code to see for yourself how the script works.

Our friends at www.webune.com have provide us with PHP hosting to show you this script in action just incase you don't have PHP but want to learn about PHP programming.

if you've learned from this howto tutorial, we would appriciate a link black to http://www.wallpaperama.com. by linking to us, you will make this tutorial guide more available to other who are looking for free information like this.

CLICK HERE TO SEE DEMO

Thanks

Wallpaperama Team
tola
#5323 1
i want to know how make clickable link when user input text in text area and in text area also has name of website example: this is the news from google please visit it. so, google is people can click to see website.
Jul 13, 2011 Reply Report abuse
valis chambas
#1650 2
dear sir, please kindly show me how to convert url text links into clickable link
Jul 23, 2009 Reply Report abuse
Sandra Miller
#1649 3
i have a question... i don't know the correct terms or names, so bare with me. i want to take a picture link from photobucket, either the hmlt or the img..... preferably the img link and make a link to in without using the whole address location. i just want it to say "click here" or the name of the subject.

i want to post on craig's list but i just want a "click here" type of link.

how do i make that?

thanks
sandra
Jan 21, 2008 Reply Report abuse
Stijn
#1648 4
hi, great script! but i want also the possibillity to choose your text that appears on the screen. does anybody has a solution for this?
Jan 10, 2008 Reply Report abuse
tomas
#1647 5
i tried

substr("", 0, 5);

doesnt work... just ignores what php sayd to do... can you make any example?
Nov 28, 2007 Reply Report abuse
me
#1645 6
you need to use the character
Nov 28, 2007 Reply Report abuse
tomas
#1646 7
hello,
how can i replace \2 to a shorter url using substr?
substr("\2", 0, 10);
how can i do this? please can you help me with it?

please post something here...
Nov 28, 2007 Reply Report abuse
sty
#1644 8
test on 3 links to see if it is my copy or implementation of the code:

google
slashdot.org
foofoo
Nov 15, 2007 Reply Report abuse
sty
#1643 9
it is just converting the first link. any ideas on how to make it convert all?
Nov 15, 2007 Reply Report abuse
sty
#1642 10
good stuff!
i am trying to make it tell if it is a youtube video link and then create the right link code around it so it is embedded. any help?
Nov 15, 2007 Reply Report abuse
Leave Your Comments...
©2012 Webune Forums - Fri Dec 14, 2012 6:57 am
Powered by: Webune Forums V3