都是通過regular expression來做的.
preg_replace是php下reg exp的功能, R大找找jsp下的相關功能.
// 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\-]+\.[\w\-.\~]+(?:/[^ \"\t\n\r<]*)?)#is", "\\1<a href=\"http://\\2\" target=\"_blank\"><font color=\"Blue\">\\2</font</a>", $ret); 有關bbcode那些reg. 看以下的部份
$searcharray['bbcode_regexp'] = array(
"/\[url\]\s*(www.|https?:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|telnet:\/\/|rtsp:\/\/|mms:\/\/){1}([^\[\"']+?)\s*\[\/url\]/ie",
"/\[url=www.([^\[\"']+?)\](.+?)\[\/url\]/is",
"/\[url=(https?|ftp|gopher|news|telnet|rtsp|mms){1}:\/\/([^\[\"']+?)\](.+?)\[\/url\]/is",
);
$replacearray['bbcode_regexp'] = array(
"<a href=\"http://www.\\1\" target=\"_blank\"><font color=\"blue\">\\2</font></a>",
"<a href=\"\\1://\\2\" target=\"_blank\"><font color=\"blue\">\\3</font></a>",
); bbcode的match於link match比較好.
|