Friday 27 July 2012

HTML line break


Inserts HTML line breaks before all newlines in a string

This code is very useful when we insert large content with number of new lines in the database table.
In case of html line, it inserts <br /> for all \n.

<?php
echo nl2br("Hello \n World");
?>
OUTPUT will be

Hello
World

1 comment:

  1. Hmm..good and useful. is it possible to use like., $var = "hi this is just for sample for testing \n nl2br method is useful or not in such a big string is assigned \n for a VARIABLE and passed as \n ARGUMENT to this?"
    nl2br($var);
    whether it ll give me expected result?

    ReplyDelete