从数据库写入csv文件,如果同一个id试图追加"评论"与同一行的coulmn。但如果数据库值以" \"结尾签名所以下一条评论是写在新行..如果值不是以" \"结尾为此工作正常。
function cleanComments($string) {
$cleanstring = trim($string);
$returnstring = preg_replace("/\n/", "", $cleanstring);
return $returnstring;
}
function remove_special_char($string) {
$RemoveChars[] = "([,%+*¢£¥¤¡~©¦§¨ª«¬®¯°±²³´µ¶¸¹º»¿\[:^print:]])";
$ReplaceWith = "";
$text = preg_replace($RemoveChars, $ReplaceWith, $string);
return $text;
}

$comment_text = cleanComments($query_result['user_name'] . ':' . $query_result['comment']);
if ($counter == 1) {
$row['comment'].= remove_special_char($comment_text);
} else {
$row['comment'].= PHP_EOL . remove_special_char($comment_text);
}

如果" \"这个特殊字符的结尾是不写在csv中排队检查我的代码我错过了什么?还是任何解决方案?
答案 0 :(得分:0)
我改变了这个。
$comment_text = cleanComments(stripslashes($query_result['user_name'] . ':' . $query_result['comment']));
if ($counter == 1) {
$row['comment'].= remove_special_char($comment_text);
} else {
$row['comment'].= PHP_EOL . remove_special_char($comment_text);
}