2017-02-26 70 views
0

我遇到了PHP问题。我想在服务器的文件.txt中保存带有特殊字符的文本,如“è”或“é”。我试过这段代码:在文件中保存带有“è”或“é”特殊字符的文本PHP

<?php 
if(isset($_POST["textbox1"]) and isset($_POST["textbox2"]) and isset($_POST["textarea1"])){ 
$file_data = file_get_contents("./posts/num.html"); 
$num = (int) $file_data; 
$num = $num + 1; 
$file_data = fopen("./posts/num.html","w+"); 
fwrite($file_data,(string)$num); 
fclose($file_data); 

$titolo = $_POST["textbox1"]; 
$sottotitolo = $_POST["textbox2"]; 
$testo = $_POST["textarea1"]; 

$date = date("d/m/y"); 

$file = fopen("./posts/".$num.".txt","w+"); 
fwrite($file,utf8_encode($titolo)."\n".utf8_encode($sottotitolo)."\n".$date."\n\n".utf8_encode($testo)); 

fclose($file); 

$ffile = fopen("./posts/".$num.".html","w+"); 
fwrite($ffile,"<br>"); 
fclose($ffile); 
?> 

使用utf8_encode,但它不工作。

非常感谢您的帮助。

我想从ISO-8859-1转换为ISO-8859-15

+0

你试图编码到utf-8的编码是什么?请注意,'utf8_encode()'[从ISO-8859-1转换为utf-8](http://us2.php.net/manual/en/function.utf8-encode.php)。 – frz3993

+0

所以我错了。我想将ISO-8859-1转换为ISO8859-15 –

+0

哪些字符正在写入文件? @ EliaD'Amato你需要在你的问题中包含确切的结果以便人们看到。 –

回答

0

我使用

header('Content-type: text/html; charset=iso8859-15'); 

解决我的问题,并出现了口音。谢谢。

相关问题