在PHP中使用nl2br()

时间:2017-03-18 06:37:58

标签: php string laravel blade nl2br

我正在使用以下代码。

OpenCart 2

我得到的输出如下

<?
echo nl2br( 'The situation deteriorated into attacks on New York elite, followed by attacks on black New Yorkers and their property after fierce competition for a decade between 
Irish immigrants and black people for work. Rioters burned the Colored Orphan Asylum to the ground.' , false  ) ;
?>

我想在没有The situation deteriorated into attacks on New York elite, followed by attacks on black New Yorkers and their property after fierce competition for a decade between <br> Irish immigrants and black people for work. Rioters burned the Colored Orphan Asylum to the ground. 的情况下获得输出,但此时我需要一个换行符(换行符)。

2 个答案:

答案 0 :(得分:0)

为什么你不能这样做..

<?
echo "The situation deteriorated into attacks on New York elite, followed by attacks on black New Yorkers and their property after fierce competition for a decade between\n Irish immigrants and black people for work. Rioters burned the Colored Orphan Asylum to the ground.";
?>

答案 1 :(得分:0)

试试这个。顺便说一下,我不知道&#34; false&#34;是什么?在字符串后面,但如果你在你的代码中删除它,它工作得很好,我看到没有html断行标记。

<?php 
$string = 'The situation deteriorated into attacks on New York elite,followed by attacks on black New Yorkers and their property after fierce competition for a decade between Irish immigrants and black people for work. Rioters burned the Colored Orphan Asylum to the ground.';
function nl2br2($string) { 
$string = str_replace(array("\r\n", "\r", "\n"), "<br />", $string); 
return $string; 
} 
echo"$string";
?>