I can convert the "newlines" to the HTML line breaks using nl2br($test)
command, but I want the command to convert all the newlines except the last one. I don't want any breaks after the last line. Could you please help me on this?
Asked
Active
Viewed 273 times
-4

someOne
- 1,975
- 2
- 14
- 20

MAHADEVASWAMY HN
- 73
- 5
-
1edit with your string and add more details, code as example – Adrian Cid Almaguer Apr 03 '15 at 07:41
-
please use the search before asking a question. thank you. – hakre Apr 03 '15 at 07:46
-
@hakre that doesn't look like an obvious duplicate, as there are additional steps to answer *this* question – Rowland Shaw Apr 03 '15 at 07:48
-
you got some advance with your problem? – Adrian Cid Almaguer May 01 '15 at 18:51
1 Answers
0
You can use this example:
When you convert your string with nl2br
and the function adds a <br />
at the end of the resulting string; then you can just eliminate the last <br />
with either substr
or rtrim
functions:
<?php
$string = "This\r\nis\n\ra\n\rtest\n\r";
$string = trim(nl2br($string));
echo $string;
echo "<br>\n";
echo substr($string, 0, -6);
echo "<br>\n";
echo rtrim($string, '<br />');
?>

someOne
- 1,975
- 2
- 14
- 20

Adrian Cid Almaguer
- 7,815
- 13
- 41
- 63