我的问题是:我正在尝试阅读*中的文字。在php中的RTF在mysql中为我的数据库添加值,一切顺利,直到我打开生成的文件,我看到没有特殊字符让我很好。这是我的代码,抱歉,这是我的第一篇文章,我不知道如何正确设置:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
ini_set("default_charset", "utf-8");
mysql_query("SET NAMES 'utf8'");
// Read rtf
$plantilla = file_get_contents('plantilla_titulo.rtf');
// Agregamos los escapes necesarios
$plantilla = addslashes($plantilla);
$plantilla = str_replace('\r','\\r',$plantilla);
$plantilla = str_replace('\t','\\t',$plantilla);
// Data in php to rtf
$nombre = $_POST["nombre"];
$curso = $_POST["curso"];
$fechahoy = date("d-m-Y", time());
//Here I Replace who shows me for special characters,
//but it doesn't works, now show me characters like " or +- ...
$plantilla = str_replace("\'d3",'Ó',$plantilla);
$plantilla = str_replace("\'f1",'ñ',$plantilla);
$plantilla = str_replace("\'f3",'ó',$plantilla);
$plantilla = str_replace("\'ed",'í',$plantilla);
$plantilla=utf8_encode($plantilla);
// Procces rtf
eval( '$rtf = <<<EOF_RTF
' . $plantilla . '
EOF_RTF;
' );
//Here i do a var_dump($rtf); and show me special characters.
// Save rtf
file_put_contents("$nombre-$fechahoy.rtf",$rtf);
echo "<a href=\"$nombre-$fechahoy.rtf\">download</a>";
?>
</body>
</html>
我已经做了一个手动“调试”,我的问题就在于这一行,因为我正在做var_dump($ rtf);并向我展示......我希望你能帮助我,谢谢你!
答案 0 :(得分:0)
首先是decode
,然后是replace
。
$plantilla = utf8_decode($plantilla);
$plantilla = str_replace("\'e1",'á',$plantilla);
$plantilla = str_replace("\'c1",'Á',$plantilla);
$plantilla = str_replace("\'e9",'é',$plantilla);
$plantilla = str_replace("\'c9",'É',$plantilla);
etc...
// Save rtf, here decode again
$rtf = utf8_decode($rtf);
file_put_contents("$nombre-$fechahoy.rtf",$rtf);