Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php在文件中写入特殊字符_Php_File - Fatal编程技术网

使用php在文件中写入特殊字符

使用php在文件中写入特殊字符,php,file,Php,File,我正在用php编写一个.txt文件。当我用一些特殊的字符创建它时,它会显示Ascii码。比如,如果我写一个字符串“我不知道”,它会显示“我不知道”。如何将其编写为人类可编辑格式 代码如下 function WriteErrorLog($IntegrationId, $errorStr){ // get integration name-------- $integrationnameQuery = "select * from integration where Integr

我正在用php编写一个.txt文件。当我用一些特殊的字符创建它时,它会显示Ascii码。比如,如果我写一个字符串“我不知道”,它会显示“我不知道”。如何将其编写为人类可编辑格式

代码如下

function WriteErrorLog($IntegrationId, $errorStr){
    // get integration name--------


    $integrationnameQuery = "select * from integration where IntegrationId = $IntegrationId";
    $queryRes = mysql_query($integrationnameQuery);
    $resRows = mysql_fetch_array($queryRes);
    $integrationName = $resRows['Name'];
    if(!file_exists('errors/'.$IntegrationId.'/'.date("Y.m.d").'_ErrorFile.txt')){
        $errorFile = 'errors/'.$IntegrationId.'/'.date("Y.m.d").'_ErrorFile.txt';
        $fh = fopen($errorFile, 'w') or die("can't open file");
        fwrite($fh, 'Integration Name: '.$integrationName."\r\n\r\n".date('Y-m-d H:i:s').': '.$errorStr."\r\n\r\n");
        fclose($fh);
    }else{
        $errorFile = 'errors/'.$IntegrationId.'/'.date("Y.m.d").'_ErrorFile.txt';
        $fh = fopen($errorFile, 'a+') or die("can't open file");
        fwrite($fh, date('Y-m-d H:i:s').': '.$errorStr."\r\n\r\n");
        fclose($fh);
    }
}

function CreateErrorLog($IntegrationId, $errorStr){
    if (!is_dir('./errors/'.$IntegrationId)) {
        mkdir('./errors/'.$IntegrationId);
        WriteErrorLog($IntegrationId, $errorStr);
    }else{
        WriteErrorLog($IntegrationId,  $errorStr);
    }
}
我就像下面一样

CreateErrorLog('120', 'I don`t know');

如果代码中有
htmlspecialchars
HTMLEntitys
,请将其删除。

您可以通过特殊代码编写特殊字符:例如\n是0x0A

也可以使用函数chr()将ASCII码转换为字符


也可以在(f | s)printf函数中使用%c<代码>printf(“零:%c”,0x30)

你现在在做什么?显示你的代码。你能显示你不工作的代码吗…?没有看到任何代码,我想说你可能只需要转义字符。i、 e.
“我不知道”
。但就像一句话,你的问题可能是无关的。