$text = preg_replace_callback('#(^|[\n ])((http|https|ftp|ftps)://[\w\#$%&~/.\-;:=,?@\[\]\(\)+]*)#is', function($matches) { return $matches[1]." ".trimlink($matches[2], 20).(strlen($matches[2])>30?substr($matches[2], strlen($matches[2])-10, strlen($matches[2])):'')." '";} ,$text); $text = preg_replace_callback("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]\(\)+]*)#is", function($matches) { return $matches[1]." ".trimlink($matches[2], 20).(strlen($matches[2])>30?substr($matches[2], strlen($matches[2])-10, strlen($matches[2])):'')." '";} ,$text); $text = preg_replace_callback("#([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#is", function($matches) { return hide_email($matches[1]."@".$matches[2]); }, $text);