$text = preg_replace_callback( '#\[url\]([\r\n]*)([^\s\'\"]*?)([\r\n]*)\[/url\]#is', function($matches) { return "".trimlink($matches[2], 20).(strlen($matches[2])>30?substr($matches[2], strlen($matches[2])-10, strlen($matches[2])):'').""; }, $text );