I am writting one .txt file using php. When I create it with some special charecter then it shows Ascii code for that. Like if I write a string "I don`t know" it shows "I don't know". how to write it as human redable format?
code is below
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);
}
}
I am accessing like below
CreateErrorLog('120', 'I don`t know');
You can write special haracters by special codes: for example \\n is 0x0A
Or you can use function chr() for convert from ASCII code to character.
Or you can use %c in (f|s)printf functions. printf("There is zero:%c", 0x30);
如果您的代码中包含htmlspecialchars
或htmlentities
,请将其删除。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.