Это тот, кого я собрал именно по той же причине. Вы можете удалить строку strip_tag (), если хотите сохранить HTML в своих сообщениях.
function convert_to_plaintext($message)
{
$message = strip_tags($message);
//Quotes: Replace smart double quotes with straight double quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
preg_replace('[\x84\x93\x94]', '"', $message);
//Quotes: Replace smart single quotes and apostrophes with straight single quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
preg_replace("[\x82\x91\x92]", "'", $message);
//Quotes: Replace straight apostrophes with smart apostrophes
preg_replace("/(\b'\b)/", "?", $message);
//Quotes: Replace straight double quotes with smart double quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
preg_replace('/(\B"\b([^"\x84\x93\x94\r\n]+)\b"\B)/', '?\1?', $message);
//Quotes: Replace straight double quotes with smart double quotes.
//Unicode version for use with Unicode regex engines.
//preg_replace('/(\B"\b([^"\u201C\u201D\u201E\u201F\u2033\u2036\r\n]+)\b"\B)/', '?\1?', $message);
$message = str_replace(array('%u201C','%u201D','%u201E','%u201F','%u2033','%u2036'),'"',$message);
//Quotes: Replace straight single quotes with smart single quotes.
//Unicode version for use with Unicode regex engines.
//preg_replace("/(\B'\b([^'\u2018\u2019\u201A\u201B\u2032\u2035\r\n]+)\b'\B)/", "?\1?", $message);
$message = str_replace(array('%u2018','%u2019','%u201A','%u201B','%u2032','%u2035'),"'",$message);
//Quotes: Replace straight single quotes with smart single quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
preg_replace("/(\B'\b([^'\x82\x91\x92\r\n]+)\b'\B)/", "?\1?", $message);
$message = str_replace("\n\n\n","\n\n",$message);
$message = str_replace("\n\n\n","\n\n",$message);
$message = str_replace("\n\n\n","\n\n",$message);
$message = str_replace("\n\n\n","\n\n",$message);
$message = str_replace("\n\n\n","\n\n",$message);
$message = str_replace("\n",'<br/>',$message);
return $message;
}