Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML_QuickForm TextArea Newline Problem

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hi there,

I'm hitting a wall of blanks with this after much experimentation and googling!

I have a page which allows "comments" to be entered via an html textarea. If the user has included a carriage return in the text they have typed this is stored in the MySQL field as "\r\n". I should point out that the form is built and rendered using HTML_QuickForm. When I come to view a frozen (i.e. read-only) version of the form, the stored "comments" field looks like this: "First line of text\r\nSecond line of text".

In the textarea.php file (i.e. the HTML_QuickForm file which controls the rendering of a textarea), the getFrozenHtml function is called and attempts to use the nl2br function to convert all the newlines to <br /> tags, as shown in the line below.
Code:
$html = nl2br($value)."\n";
However, after using this function the "\r\n" remains in the string. I've done a var_dump before and after the nl2br call and $value contains exactly the same string throughout.

Does anyone know how to solve this one?

Your advice would be much appreciated.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
does this replacement code work?
Code:
 function getFrozenHtml()
    {
        $value = $this->getValue();
        if ($this->getAttribute('wrap') == 'off') {
            $html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
        } else {
            $html = nl2br($value)."\n";
        }
        return htmlspecialchars($html) . $this->_getPersistantData();
    } //end func getFrozenHtml
 
actually, i don't think that's the right answer.

can you point us to a live site with this problem? i'd like to check out the html source.
 
Stretchwickster said:
However, after using this function the "\r\n" remains in the string.
According to PHP Manual, nl2br does not replace \n with <br />, it inserts <br /> before \n. So, the string should still contain the newline element, but since HTML is white-space agnostic, that newline will simply be ignored (it only helps if you look at the source code). Why exactly do you want to get rid of the newlines in your string?

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
What I'm thinking is that he's got magic_quote_gpc set to "on", which automatically escapes "\r"s and "\n"s. So when he runs nl2br() against the string, the function never sees the two characters 0x0D 0x0A but rather sees the four-character string '\r\n'.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks for all your suggestions guys. I've been diverted onto another project for the time being. However, I will be returning to this sometime soon and will respond properly in due course.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top