Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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 防止MySQL LONGSTRING值的回车丢失_Php_Mysql - Fatal编程技术网

Php 防止MySQL LONGSTRING值的回车丢失

Php 防止MySQL LONGSTRING值的回车丢失,php,mysql,Php,Mysql,我在MySQL的LONGSTRING值中丢失回车时遇到了一个问题。当我使用echo时,我不知道变量是否保存回车符,或者回车符是否丢失。这是我的一段代码。代码假定MySQL查询已经运行 $longstringValue = $row['longstringValue']; // The value from the database has carriage returns... echo $longstringValue // but they are

我在MySQL的LONGSTRING值中丢失回车时遇到了一个问题。当我使用
echo
时,我不知道变量是否保存回车符,或者回车符是否丢失。这是我的一段代码。代码假定MySQL查询已经运行

$longstringValue = $row['longstringValue']; // The value from the database has carriage returns...
echo $longstringValue                       // but they aren't present when I echo the variable.

如何停止此操作?

换行符和回车符在HTML中没有(视觉)意义,因此如果需要这些换行符进行渲染,请在某个时候运行函数,如手册所示:

<?php
    echo nl2br("foo isn't\n bar");
?>

因此,当存储在PHP变量中时,MySQL LONGSTRING值中的回车是
\n
。@DavidB它取决于输入方法。它可以是
\r
\n
,或两者的组合;如手册所述,nl2br可处理所有这些问题。
foo isn't<br /> bar