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



How To Make Clickable Text URL Links From Text Links Change To Clicking
How To Make Clickable Text URL Links From Text Links Change To Clicking
Post Description:
Post Tags: how, to, make, clickable, text, url, links, from, text, links, change, to, clicking
This Post Has Been Viewed 6995 Times Since Thu Dec 21, 2006 7:44 pm Posted By webmaster with 11 replies
How To Make Clickable Text URL Links From Text Links Change To Clicking
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

Leave Your Comments     [ dejar commentarios ]
  * Name     [nombre]

  * eMail (will not be published)     [coreo electronico]

* Enter Your Reply or Comments:    [commentarios]


Add Picture To Comments         [incluir foto]
YES NO             upload
Receive Replies on my Comments (An email will be sent to you when someone replies to your comments)

     

Comments and replies About How To Make Clickable Text URL Links From Text Links Change To Clicking




:: 1 :: #27844 - Reply By sty On Thu Nov 15, 2007 3:04 pm
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?
:: 2 :: #27845 - Reply By sty On Thu Nov 15, 2007 3:06 pm
it is just converting the first link. any ideas on how to make it convert all?
:: 3 :: #27846 - Reply By sty On Thu Nov 15, 2007 3:07 pm
test on 3 links to see if it is my copy or implementation of the code:

google
slashdot.org
foofoo
:: 4 :: #29608 - Reply By tomas On Wed Nov 28, 2007 1:02 pm
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...
:: 5 :: #29636 - Reply By me On Wed Nov 28, 2007 5:01 pm
you need to use the \ character
:: 6 :: #29653 - Reply By tomas On Wed Nov 28, 2007 9:43 pm
i tried

substr("\", 0, 5);

doesnt work... \ just ignores what php sayd to do... can you make any example?
:: 7 :: #35693 - Reply By Stijn On Thu Jan 10, 2008 12:47 am
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?
:: 8 :: #37635 - Reply By Sandra Miller On Mon Jan 21, 2008 10:26 pm
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
:: 9 :: #47401 - Reply By sharika On Thu Mar 27, 2008 6:45 pm
hey hello love yuo
:: 10 :: #52424 - Reply By Ali On Fri May 02, 2008 3:09 am
hey thanks for great script - i am struggling with finding a way to truncate the display text of the link (very long links break my css) whilst leaving the url intact in the link - can regex do this? my regex is rubbish otherwise i guess i wouldn't be here ;)
:: 11 :: #56300 - Reply By Qaseem On Tue Jun 03, 2008 3:41 am
online buying and selling on internet
in all pakistan.