Search the Community
Showing results for tags 'nl2br'.
-
Hi All, I am facing an issue I cannot solve and I just do not understand why. In a db table, I've got a field that contains text coming from a textarea in a form. If the user had entered breaklines to divide their text into paragraphs, the breaklines are replaced with "\r\n" strings, so the text in the table field may look like "Hello\r\nHow are you?". This works. Now, assuming that the user wishes to edit that text, I want to retreive that text into a textarea, with the same paragraph layout as that initially used by the user. Here is my code (without the whole db error checking code) : $link = @mysql_connect('localhost', 'root', ''); mysql_select_db('mydb', $link); $sql = 'SELECT * FROM table_name Where field_id="31"'; $rs = mysql_query($sql, $link); $arr = mysql_fetch_array($rs); $txt =$arr['user_input']; $txt = nl2br($txt); echo '<br />retrieved text from db is ' .$txt.'<br />';//Will display "retrieved text from db is Hello\r\nHow are you?" $txt=str_replace("<br />", "", $txt); echo '<br /><textarea name="text" cols="100" rows="15" >'.$txt.'</textarea>';// Will display "Hello\r\nHow are you?" in the textarea Now if manually set a variable called "Hello\r\nHow are you?". The following code $string = "Hello\r\nHow are you?"; $string=nl2br($string); $string=str_replace("<br />", "", $string); echo '<br /><textarea name="text2" cols="100" rows="15" >'.$string.'</textarea>'; Will generate "Hello How are you?" in the textarea. Why can't I manage to make this work with the text retreived from the database ? Thanks for your help. Phd