Make Clickable

Alles, was PHP betrifft, kann hier besprochen werden.

Make Clickable

Postby HardySim » 30. August 2003 17:03

hey, ich versuch in meinem eigenen gästebuch die function aus phpBB make_cliackable zu benutzen...

sieht eigentlcih so aus, als sollte es funzen, nur tuts net ;) hier die function:
/**
* Rewritten by Nathan Codding - Feb 6, 2001.
* - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
* to that URL
* - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking
* to http://www.xxxx.yyyy[/zzzz]
* - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking
* to that email address
* - Only matches these 2 patterns either after a space, or at the beginning of a line
*
* Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe
* have it require something like xxxx@yyyy.zzzz or such. We'll see.
*/
function make_clickable($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("#([\t\r\n ])([a-z0-9]+?){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a href="\2://\3" target="_blank">\2://\3</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("#([\t\r\n ])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a href="http://\2.\3" target="_blank">\2.\3</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);
}


also müsste ich doch dann in meinem GB zum bsp.

make_clickable($eintrag); eintragen, damit er aus der var $eintrag in der function ein $text macht, sie verwendet und sie wieder als $eintrag ausgibt, oder?

es kommt zwar der eingegebene text, aber halt ohne link, einfach nur blanker text. hat jemand ne idee und kann mir helfen?
[url=http://www.hardysim.de]
Image[/url]
www.party-safari.net
User avatar
HardySim
 
Posts: 325
Joined: 19. June 2003 10:22
Location: Geisenheim

Return to PHP

Who is online

Users browsing this forum: No registered users and 12 guests