# typo found in ext/standard/string.c, inside function nl2br, php 5.3.0 svn trunk

- Thread: https://externals.io/message/45965
- Original archive: https://news-web.php.net/php.internals/45965
- Started by daqing on 2009-11-06T03:18:38+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #45965 — daqing — 2009-11-06T03:18:38+00:00

URL: https://externals.io/message/45965#45965

hi, all:

I just found a typo today when I read the source code of function nl2br,
here is what 'svn diff' produce against the php 5.3.0 svn trunk:

Index: ext/standard/string.c
===================================================================
--- ext/standard/string.c       (revision 290364)
+++ ext/standard/string.c       (working copy)
@@ -3918,7 +3918,7 @@
        tmp = str;
        end = str + str_len;

-       /* it is really faster to scan twice and allocate mem once insted
scanning once
+       /* it is really faster to scan twice and allocate mem once instead
scanning once
           and constantly reallocing */
        while (tmp < end) {
                if (*tmp == '\r') {


besides, I have a question: why not function nl2br just replace the "\r\n",
"\n", "\r" things with "<br/>"? why insert "<br/>" before those "\r\n",
"\n", "\r"?

regards,

Kinch Zhang



-- 

"Simplicity is the essence of happiness."

---

## #45967 — Scott MacVicar — 2009-11-06T09:05:15+00:00

URL: https://externals.io/message/45965#45967 · In reply to: #45965

> hi, all:
>
> I just found a typo today when I read the source code of function  
> nl2br,
> here is what 'svn diff' produce against the php 5.3.0 svn trunk:
>
> Index: ext/standard/string.c
> ===================================================================
> --- ext/standard/string.c       (revision 290364)
> +++ ext/standard/string.c       (working copy)
> @@ -3918,7 +3918,7 @@
>        tmp = str;
>        end = str + str_len;
>
> -       /* it is really faster to scan twice and allocate mem once  
> insted
> scanning once
> +       /* it is really faster to scan twice and allocate mem once  
> instead
> scanning once
>           and constantly reallocing */
>        while (tmp < end) {
>                if (*tmp == '\r') {


This typo and the grammatical error are fixed now.

>
>
> besides, I have a question: why not function nl2br just replace the  
> "\r\n",
> "\n", "\r" things with "<br/>"? why insert "<br/>" before those "\r 
> \n",
> "\n", "\r"?
>

Because its much easier to read the output when the newlines are  
preserved.

Scott

---

## #45969 — mm w — 2009-11-06T16:00:07+00:00

URL: https://externals.io/message/45965#45969 · In reply to: #45967

say CR LF carriage return and line feed, yes those characters could
be trimmed, I think it's a choice to keep the original input you could
redefine a function if your are no happy with it or even add an
optional param to the C function: bool  preserveCRLF, I am not really
convinced by Scott argument 8-)


> 
>
>
> hi, all:
>
> I just found a typo today when I read the source code of function nl2br,
> here is what 'svn diff' produce against the php 5.3.0 svn trunk:
>
> Index: ext/standard/string.c
> ===================================================================
> --- ext/standard/string.c       (revision 290364)
> +++ ext/standard/string.c       (working copy)
> @@ -3918,7 +3918,7 @@
>        tmp = str;
>        end = str + str_len;
>
> -       /* it is really faster to scan twice and allocate mem once insted
> scanning once
> +       /* it is really faster to scan twice and allocate mem once instead
> scanning once
>           and constantly reallocing */
>        while (tmp < end) {
>                if (*tmp == '\r') {
>
>
>
> This typo and the grammatical error are fixed now.
>
>
>
>
> besides, I have a question: why not function nl2br just replace the "\r\n",
> "\n", "\r" things with "<br/>"? why insert "<br/>" before those "\r\n",
> "\n", "\r"?
>
>
>
> Because its much easier to read the output when the newlines are preserved.
>
> Scott
