Forum Moderators: coopster
All I want is that when someone inputs "visit this great site: [webmasterworld.com"...] that it automatically makes it a link.
It can do it either when it's being entered into the database or when it's being displayed on the site.
Webmasterworld does this somehow but only on links with "http://" at the beginning, I'd want to do it if the http were there or not...
i.e.
<?php
echo add_hrefs($displaytext); //outputs text and adds a hrefs
?>
and we'd just have to make some kind of function and name it add_hrefs.
or maybe I'm going about this all wrong I don't know...
Anyone have any suggestions?
Thanks,
-Jason
function urlify($html, $target)
{
// Look for valid address in a block of text,
// Convert it to a html url (watching for punctuation or end of string)
$pattern ="{\\b((https?¦telnet¦gopher¦file¦wais¦ftp) : [\\w/\\#~:.?+=&%@!\\-]+?) (?= [.:?\\-]* (?:[^\\w/\\#~:.?+=&%@!\\-] ¦$) ) }x";
return preg_replace ($pattern, "<a href=\"$1\" target=\"" . $target . "\">$1</a>", $html);
}
It'll only work with functions prepended by the transfer protocol (not quite what you wanted), but it is quite accurate in picking out a proper URL.
I tried this:
$text="hello, welcome to wwWebmasterWorldebsite.com";
$text = preg_replace('/(?<!=)(?<!])(http¦ftp)+(s)?:(\/\/)((\w¦\.)+)(\/)?(\S+)?/i','<a href="\0">\0</a>', $text);
echo $text . "<br><br><br>";
$text="hello, welcome to [wwWebmasterWorldebsite.com";...]
$text = preg_replace('/(?<!=)(?<!])(http¦ftp)+(s)?:(\/\/)((\w¦\.)+)(\/)?(\S+)?/i','<a href="\0">\0</a>', $text);
echo $text;
but it didn't seem to do anything, just output the text, no links.
I'm going to try the other method listed