Posted on: 11/14/03 02:18am
By: narres
Hi Geeks,
is there a way to integrate some automated href substitution so that somesting like:
http://linux.24x.info/news/
is allways converted to
http://linux.24x.info/[*1] ?
I know to do it whith:
$text = ereg_replace("[[:alpha:]]+://([^[:space:]]+[[:alnum:]/])","
\1", $text);
But how integrate this into the template for {text_body}?
Re:Automated href tag
Posted on: 11/17/03 10:12am
By: Turias
Well, do you want to do the replace on submission or when it is displayed? And do you want it to happen for stories? Forum posts? Events? Everything?
Automated href tag
Posted on: 02/09/04 08:27am
By: pibby
I am also very interested in something like this for stories. Where would I put that code?Has anyone tried it?
Automated href tag
Posted on: 02/09/04 10:50am
By: Anonymous (FreakWorld)
Ya this will be great for stories.
I keep getting people that don't know basic html submitting stories with urls. And thin I have to go through the hole thing and fix it. This will be cool if someone figures it out.
(I bet thats whats somone is thinking about this post. You don't know basic php and now we have to go and fix it.)
Automated href tag
Posted on: 04/15/04 04:46am
By: Anonymous (rakaz)
I use the following function for converting URLs plain text to clickable links. I run this function on the submitted text of a comment before saving it in the database, so this function isn't run everytime somebody views the comment.
You could probably insert something like this also on the submission pages of stories and other user submitted text.
function COM_convertURLs ( $text )
{
// First match things beginning with http:// (or other protocols)
$NotAnchor = '(?<!"|href=|hrefs=s|href=s|hrefs=)';
$Protocol = '(http|ftp|https)://';
$Domain = '[w]+(.[w]+)';
$Subdir = '([w-.;,@?^=%&:/~+#]*[w-@?^=%&/~+#])?';
$Expr = '/' . $NotAnchor . $Protocol . $Domain . $Subdir . '/i';
$text = preg_replace( $Expr, "<a href="$0" target="_blank">$0</a>", $text );
// Now match things beginning with www.
$NotAnchor = '(?<!"|-|href=|hrefs=s|href=s|hrefs=)';
$NotHTTP = '(?<!://)';
$Domain = 'www(.[w]+)';
$Subdir = '([w-.;,@?^=%&:/~+#]*[w-@?^=%&/~+#])?';
$Expr = '/' . $NotAnchor . $NotHTTP . $Domain . $Subdir . '/i';
return preg_replace( $Expr, "<a href="http://$0" target="_blank">$0</a>", $text );
}
This function is based on an example found on php.net, but modified to make it handle certain exceptions better.