更新时间:2023-02-23 13:56:50
我为此创建了一组非常基本的正则表达式.不要期望它们 100% 可靠,您可能需要随时调整它们.
I have created a very basic set of Regular Expressions for this. Don't expect them to be 100% reliable, and you may need to tweak them as you go.
$pattern = array(
'/((?:[\w\d]+\:\/\/)?(?:[\w\-\d]+\.)+[\w\-\d]+(?:\/[\w\-\d]+)*(?:\/|\.[\w\-\d]+)?(?:\?[\w\-\d]+\=[\w\-\d]+\&?)?(?:\#[\w\-\d]*)?)/' , # URL
'/([\w\-\d]+\@[\w\-\d]+\.[\w\-\d]+)/' , # Email
'/\[@([^\]]*)\]/' , # Reply
'/\[([^\]]*)\]/' , # Bold
'/\{([^}]*)\}/' , # Italics
'/_([^_]*)_/' , # Underline
'/\s{2}/' , # Linebreak
);
$replace = array(
'<a href="$1">$1</a>' ,
'<a href="mailto:$1">$1</a>' ,
'<b class="reply">@$1</b>' ,
'<b>$1</b>' ,
'<i>$1</i>' ,
'<u>$1</u>' ,
'<br />'
);
$msg = preg_replace( $pattern , $replace , $msg );
return stripslashes( utf8_encode( $msg ) );