★ wanayoo — archive 1999 http://www.php.net/manual/fr/function.nl2br.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Chaînes
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageItalian version of this pageHungarian version of this page
Chaînes
* AddCSlashes
* AddSlashes
* bin2hex
* Chop
* Chr
* chunk_split
* convert_cyr_string
* count_chars
* crypt
* echo
* explode
* flush
* get_html_translation_table
* get_meta_tags
* htmlentities
* htmlspecialchars
* implode
* join
* ltrim
* md5
* Metaphone
* nl2br
* Ord
* parse_str
* print
* printf
* quoted_printable_decode
* QuoteMeta
* rawurldecode
* rawurlencode
* setlocale
* similar_text
* soundex
* sprintf
* strcasecmp
* strchr
* strcmp
* strcspn
* strip_tags
* StripCSlashes
* StripSlashes
* stristr
* strlen
* strpos
* strrchr
* str_repeat
* strrev
* strrpos
* strspn
* strstr
* strtok
* strtolower
* strtoupper
* str_replace
* strtr
* substr
* substr_replace
* trim
* ucfirst
* ucwords
Manual: nl2br
View the source code for this pageSearch the site



Previous page
 Metaphone
 Updated
Sun, 06 Aug 2000
Ord 
Next page


nl2br

(PHP3 , PHP4 )

nl2br -- Converti les nouvelles lignes en HTML (<BR≶).

Description

string nl2br (string string)

Retourne la chaîne string dont toutes les lignes ont été remplacées par '<BR>'.

Voir aussi htmlspecialchars() et htmlentities().


User Contributed Notes: nl2br


davidbullock@tech-center.com
22-Nov-1999 11:06
If you use nl2br in conjunction with htmlspecialchars, you should process the string with nl2br after htmlspecialchars to prevent htmlspecialchars from escaping your newly generated
symbols.



chrisr@broadcastmusic.com
13-Jan-2000 01:59
Why no br2nl?
Granted it's easy to write a br2nl, but the same could be said of nl2br.



howardh@telus.net
04-Mar-2000 02:28
the above doesn't seem make sense. a newline char should be "\n", therefore the str_replace should be as follows:
<pre>
str_replace("
","\n",$s);
</pre>
This will return the string back to a reasonable semblance of its former self (prior to nl2br).



stefan@desire.ch
25-Apr-2000 05:54
i had the "black box" problem. i now use


$text = str_replace("\r\n","
",$text);


which seems to work (what the heck is \r !?)



kris@mha.ca
25-Apr-2000 08:22
The black box (its because windows doens't have a font character to display the \r) and \r\n are windows'isms. To windows a linefeed(\n) doesn't mean anything by itself, and it needs a carriage return (\r) for the newline to be valid. That is why a CrLf (carriage return linefeed) is required (\r\n) in windows, and not in unix. The black box you see is because php's nl2br is stripping the \n but not the \r. I guess the only solution in windows is not use nl2br and use <PRE>$value = str_replace("\\r\\n","
",$value);
</PRE>



fsace@hotmail.com
08-May-2000 02:12
i have found if i use str_replace("\n", "
", $s);
works but sometimes leaves the newline.

so i split it into an array:

$arr = explode("\n", $s);
$n = 0;
while ($n < count($arr)) {
$arr[$n] = Chop($arr[$n]) . "
";
$n++;
}
$ss = implode("", $arr);




max@tocrawl.com
08-Jul-2000 11:38
I need to get submitted text into MySQL DB and then on requerst pull it out in HTML format, submission field has breaks, I mean if in text area you hit return it makes a line for you. nl2br will replace all those lines with
<PRE>





</PRE>

but, as every webmaster knows

tag is much better then a couple
s .

Any Idea how to change/replace 2 BRs with one P tag?

Thanks



max@tocrawl.com
08-Jul-2000 11:42
Sorry, above I was using &lt;&gt; which didn't show up....


what I was saing was:



I need to get submitted text into MySQL DB and then on requerst pull it out in HTML format, submission field has breaks, I mean if in text area you hit return it makes a line for you. nl2br will replace all those lines with
<PRE>
&lt;BR&gt;

&lt;BR&gt;
</PRE>

but, as every webmaster knows &lt;P&gt; tag is much better then a couple &lt;BR&gt;s .

Any Idea how to change/replace 2 BRs with one P tag?

Thanks



malcolmf@nkaos.com
13-Jul-2000 02:21
As I sit here trying to conform code to a clients XML-compatible standard I get to thinking that maybe it should be replacing \n with <BR /> instead of
, just a thought....



jen_woodhead@hotmail.com
28-Jul-2000 05:04
I ithnk the problem that you are hitting concerns, windows using /r/n, unix using /n and the mac using /r all to represent the end of the line. This can inpart be remedied by using DOS2UNIX (not php) or by using reg exps to remove both symbols.


 About Notes


Previous page
 Metaphone
 Updated
Sun, 06 Aug 2000
Ord 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.