此函数将 UTF-8 字符串转换为 RTF 代码字符串。我正在使用 v0rbiz at yahoo dot com 的代码,感谢!
function cadena_rtf($txt)
{
$result = null;
for ($pos = 0; $pos < mb_strlen($txt); $pos++) {
$char = mb_substr($txt, $pos, 1);
if (!preg_match("/[A-Za-z1-9,.]/", $char)) {
//Unicode ord 真实值!
$k = mb_convert_encoding($char, 'UCS-2LE', 'UTF-8');
$k1 = ord(substr($k, 0, 1));
$k2 = ord(substr($k, 1, 1));
$ord = $k2 * 256 + $k1;
if ($ord > 255) {
$result .= '\uc1\u' . $ord . '*';
} elseif ($ord > 32768) {
$result .= '\uc1\u' . ($ord - 65535) . '*';
} else {
$result .= "\\'" . dechex($ord);
}
} else {
$result .= $char;
}
}
return $result;
}