我尽量避免问愚蠢的问题,但由于某种原因,这不起作用。我正在从数据库中检索一些文本,其中包括换行符。直接使用 echo 时,输出如下:
=== BOLD TEXT ===\nHere is some text.
这就是我检索它的方式:
$row = $query->row();
$content=$row->course_content;
以下都没有任何效果......
$content= str_replace(array("\r\n", "\r", "\n"), "<br />", $content);
$content= str_replace("\n", " ", $content);
$content = nl2br($content);
但是,当我将其硬编码为原始语句的字符串时,
$content="=== BOLD TEXT ===\nHere is some text.";
砰!它可以工作......关于它为什么拒绝接受数据库输入的任何想法,但手动字符串很好?
完整代码:
//Switch between these two:
$row = $query->row();
$content=$row->course_content;
$content="=== BOLD TEXT ===\nHere is some text.";
$content = str_replace(array("\r\n", "\r", "\n"), "<br />", $content);
$content = str_replace("\n", " ", $content);
$content = nl2br($content);
echo $content;