【问题标题】:Save a text with special characters as "è" or "é" in a file PHP将带有特殊字符的文本保存为文件 PHP 中的“è”或“é”
【发布时间】:2017-02-26 20:06:20
【问题描述】:

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

<?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

【问题讨论】:

  • 您尝试从哪种编码编码为 utf-8?注意utf8_encode()converts from ISO-8859-1 to utf-8.
  • 所以我错了。我想将 ISO-8859-1 转换为 ISO8859-15
  • 什么字符被写入文件? @EliaD'Amato 您需要在问题中包含确切的结果才能让人们看到。
  • 您需要像我之前一样使用@ ping 我,后跟我的姓名或任何其他成员的姓名。我已经留下了这个问题,因为我不能让这个问题保持太久。

标签: php


【解决方案1】:

我用

解决了我的问题
header('Content-type: text/html; charset=iso8859-15');

然后重音出现了。谢谢。

【讨论】:

    猜你喜欢
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-16
    • 2011-03-13
    相关资源
    最近更新 更多