PHP/Utility Function/nl2br

Материал из Web эксперт
Перейти к: навигация, поиск

convert the newlines to

   <source lang="html4strict">

<?php

  $recipe = "3 
  1
  8
  3";
  // convert the newlines to 
"s. echo nl2br($recipe);

?>

 </source>
   
  


nl2br() function converts all newline (\n) characters to their HTML equivalent
.

   <source lang="html4strict">

Its syntax is: string nl2br (string string) <?

   $text_recipe = "
   A
   B
   V";
   $html_recipe = nl2br ($text_recipe);
   print $html_recipe;

?>

 </source>
   
  


string nl2br ( string string ): changes any new line characters found in the data string into
.

   <source lang="html4strict">

<?php $astring = "Hello\nWorld\n\nHow are you?"; echo nl2br ($astring); ?>

 </source>
   
  


string nl2br ( string str ) inserts a HTML line break (
) before all new line characters

   <source lang="html4strict">

<?

   $mystr = "This is a test\nYes it is.";
   $brstr = nl2br($mystr);

?>

 </source>
   
  


Wrapping Text with wordwrap() and nl2br()

   <source lang="html4strict">

<?php

   $string = "one line\n";
   $string .= "another line\n";
   $string .= "a third for luck\n";
   print nl2br( $string );

?>

 </source>