注意:如果文本URL后面有『<』,要过滤,否则出错。
plain2link(obj.innerHTML.replace(/<br[^>]*>/gi, "\n<br />"));
将文本URL后面的『<b />』用换行过滤!
config.php,定义全局:
function plain2link(text){
if(!text) return text;
text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi, function(url){
nice = url;
if(!url.match('^https?:\/\/')){
url = 'http://'+url;
}
return '<a target="_blank" rel="nofollow" href="'+ url +'">'+ nice +'</a>';
});
return text;
}
One Comment
试过了,好像有错误阿