我遇到 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 中没有(视觉)含义,因此如果您需要这些换行符来渲染,请运行 nl2br 在某个时刻起作用,如手册中所示:
<?php
echo nl2br("foo isn't\n bar");
?>
输出
foo isn't<br /> bar
呈现为
foo isn't
bar
关于php - 防止 MySQL LONGSTRING 值丢失回车符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24988928/