2017-02-26 73 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'); 

解決我的問題,並出現了口音。謝謝。

相關問題