How Do I Make My Text Clickable
- Forums
- PHP
- How Do I Make My Text Clickable
This Page Contains information about How Do I Make My Text Clickable By petruslima in category PHP with 2 Replies. [2023], Last Updated: Mon Jun 24, 2024
petruslima
Thu Apr 24, 2008
2 Comments
400 Visits
i have a forums and i dont want my users to use html to i want it so that everytime they submit a link url i want my script to recognize it and make it into and clickable link on my website
is that hard to do with php?
here is a php code. just copy and past to notepad and save it as webune.php and upload to your php website and open it with your browser and see it in action
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.webune.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 "Howto" tutorial, we would appreciate if you can provide a link to our http://www.webune.com. By linking to webune, you will make these tutorials more available to others who are looking for information like this.</p>
<p>Thank You</p>
<p>webune Team</p>
<p><a href="http://www.webune.com/forums"><< Go Back</a> </p>
<p align="center">PHP Hosting by <a href="http://www.webune.com">Webune.com</a> </p>
<p>
</BODY>
</HTML>
hope this helps
https://www.webune.com/forums/how-do-i-make-my-text-clickable.html