我想在DB中插入一个类似的字符串,但插入字符“\ n”后消失,并在数据库中将其视为新行。将字符串插入MySQL后,字符' n'(换行符)消失
我发送的字符串:
[{"Index":0,"Title":"headline","Content":"first line\nsecond line","Class":"colour1"}]
对于插入到数据库中,我使用这个PHP代码和字符串我通过HTML表单与发送POST方法。
if ($action == "save") {
$notes = $_POST['notes'];
$sql = "INSERT INTO notes (notes) VALUES ('$notes')";
if (mysqli_query($conn, $sql)) {
$saved = "Saved...";
} else {
$saved = "Error: " . mysqli_error($conn);
}
}
当我通过表单发送之前打印变量“$ _ POST [‘笔记’]”或“$笔记”,该字符串是OK,发送表格后插入到数据库之前,该字符串是OK太。
尝试:'str_replace('\ n',' ',$ _POST ['notes']);'http://stackoverflow.com/questions/8627902/new-line-in-text-area –