Re: [PHP-DEV] Problem with KDE Konqueror and PHP's nl2br() in handling carriage return and newline pairs. From: Robert B. Easter (reaster <email protected>)
Date: 12/20/00

I already made the tiny change to string.c for nl2br() in my copy of PHP and
it fixed the problem discussed below. The "\r\n<br>" instead of "\r<br>\n"
works with konqueror now.

On Wednesday 20 December 2000 11:16, Robert B. Easter wrote:

> > Konqueror shows odd behavior when rendering html containing carriage
> returns ('\r' 0x0d ^M) that are not paired with a newline ('\n' 0x0a ^J).
>
> In a <textarea> in a <form>, text is entered that contains "\r\n" when the
> user presses the Enter key to begin a new line. This input from the user
> then goes to PHP's nl2br() function which replaces occurrences of '\n' with
> "<br>\n". So an occurrence of "\r\n" becomes "\r<br>\n" leaving an
> unpaired '\r'. I think that nl2br() should instead replace '\n' with
> "\n<br>" so that "\r\n" becomes "\r\n<br>". This would keep the "\r\n"
> pairs together and make Konqueror happy. Netscape has no problem with this.
>
> Attached are two html files. One has instances "\r<br>\n" in it caused by
> nl2br(), the other file has been brought into kwrite and then resaved.
> Kwrite is smart enough to detect the unpaired carriage returns, which are
> not normally used in a UNIX text file (a unix text file just uses a '\n' at
> the end of a line, whereas MSDOS uses "\r\n"), and treats the file as an
> MSDOS text file. Kwrite creates "\r\n" pairs throughout the file matching
> every lone '\n' with a '\r' in front of it, and every lone '\r' that it
> finds with a '\n' after it.
>
> Konqueror does not treat "\r<br>\n" the same as "\r\n<br>" in all
> situations. For instance, with unpaired carriage returns:
>
> <a href="file.html">file</a>^M<br>
> ^M<br>
> ^M<br>Hello,
> ^M<br>
> ^M<br>there
> ^M<br>
> ^M<br>how are you?
>
> was giving me:
>
> file
> Hello,
> there
> how are you?
>
> Without the unpaired carriage returns (^M):
>
> <a href="file.html">file</a>
> <br>
> <br>
> <br>Hello,
> <br>
> <br>there
> <br>
> <br>how are you?
>
> gave me:
>
> file
>
> Hello
>
> there
>
> how are you?
>
>
> The <a> tag makes a difference for some reason. If you remove it or put it
> at the end, then the output is the same:
>
> ^M<br>
> ^M<br>Hello,
> ^M<br>
> ^M<br>there
> ^M<br>
> ^M<br>how are you?
> ^M<br><a href="file.html">file</a>^M<br>
>
> gave me:
>
> Hello
>
> there
>
> how are you?
>
> file
>
>
> If this isn't clean enough or no one can duplicate this, I can try to
> explain again or make an better example. View the attached html files in
> Konqueror. The paired.html file is slightly larger after kwrite added '\r'
> and some '\n' to the file to make pairs.

----------------------------------------
Content-Type: /; charset="iso-8859-1"; name="Attachment: 1"
Content-Transfer-Encoding: 7bit
Content-Description:
----------------------------------------

-- 
-------- Robert B. Easter  reaster <email protected> ---------
- CompTechNews Message Board   http://www.comptechnews.com/ -
- CompTechServ Tech Services   http://www.comptechserv.com/ -
---------- http://www.comptechnews.com/~reaster/ ------------

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>