cakePHP v2.x - 显示数据库字段之外的内容

时间:2013-04-07 15:52:44

标签: cakephp

初学者提问:为什么cakePHP在使用时不显示回车/换行和其他字符;

<?php echo h($property['Property']['fullDesc']); ?>  

我尝试使用

<?php echo $property['Property']['fullDesc']; ?>

但都将文本输出显示为一个文本块而不是段落。

任何帮助都非常感激。

2 个答案:

答案 0 :(得分:4)

h函数只是php htmlspecialchars()函数的包装器。它不会将回车转换为<br />标签。你需要做这样的事情:

echo nl2br(h($property['Property']['fullDesc']));

答案 1 :(得分:1)

基本PHP ...

<?php echo nl2br(h($property['Property']['fullDesc'])); ?>  

nl2br()会将这些换行符组成<br>

提示:您可以让您的烘焙模板自动包含所有textarea字段。 见http://www.dereuromark.de/2012/04/24/cake-bake-custom-templates-deluxe/

相关问题