Использование nl2br() в PHP

Я использую приведенный ниже код.

<?
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.

Я хотел бы получить вывод без <br> но мне нужен разрыв строки (Новая линия) в этой точке.

2 ответа

Попробуй это. Кстати, я не знаю, что с "ложным" за строкой, но если вы удалите его в своем коде, он работает просто отлично, и я не вижу 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";
?>

Почему ты не можешь просто сделать это..

<?
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.";
?>
Другие вопросы по тегам