php - 如何在PHP的sqlite中插入新行?

标签 php sqlite insert newline

我使用PHP是为了在sqlite数据库中插入数据。

我有一个类似以下的字符串:

$string =  "Good morning!<br />It is a wonderful day!<br />"


我想用<br />替换所有出现的\n

为了替换<br />,我在PHP中做了以下操作,但是它不起作用:

<?php
    $string =  "Good morning!<br />It is a wonderful day!<br />"
    $symbols =array('<br />');
    $replace_symbols = array('\\n');
    $string = str_replace($symbols, $replace_symbols,$string);
    //InsertIntoSqlite($db,$string);
?>


当我使用SQLITE Manager连接到sqlite数据库时,在数据库中看到以下内容:


sqlite: Good morning!\nIt is a wonderful day!\n


为了解决这个问题我该怎么做?

解决了:

我做了以下事情:

<?php

    $string = str_replace("<br />","\n",$string);

 ?>

最佳答案

'引号的字符串不接受任何转义符,除了转义符本身。 '\t'不是制表符,它是一个\,后跟一个t。您要改为"\n",这是实际的换行符。

echo '\\ \t \n \r'; // spits out: \ \t \n \r
echo "\\ \t \n \r"; // spits out \ [tab] [newline] [carriagereturn]

关于php - 如何在PHP的sqlite中插入新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25792603/

相关文章:

mysql - SQL : Insert doesn't work

php - 在数据库 MYSQL 中插入数据,数据混合

php - 为什么 iterator_apply 示例中需要第三个参数

php - 'Warning : mysql_fetch_array() expects parameter 1 to be resource, boolean given in...' 但我的查询是正确的

android - 应用程序崩溃并给出运行时错误执行未恢复的 Activity 暂停

macos - sqlite导入Mac

php - INSERT 上的 SQL 注入(inject)

javascript - 通过 ajax 调用在 wordpress 中使用 do_shortcode

php - 如何在 Ikariam (MMORPGs) 中创建像 'build building' 这样的函数,当用户不在网站上时它会继续计数

Python SQL 到 pandas DataFrame 2