Skip site navigation (1) Skip section navigation (2)

Re: newlines won't display in browser

From: Robby Russell <rrussell(at)commandprompt(dot)com>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: newlines won't display in browser
Date: 2003-10-13 14:35:58
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-php
Michael Hanna wrote:
> Hi,
> hi, how do you put a newline in a TEXT data type?
> when inputting from a form into a textarea box..the return key creates a 
> newline, which is reflected in psql monitor but not when displaying the 
> page with php
> when I try inputting \n in the browser textarea form, they appear in the 
> webpage for some reason, in psql monitor, they appear as "\n" but also 
> make a newline
> Michael
I'd suggest doing this in your postgresql statement. Makes it easy when 
you use views and don't want to use php functions everywhere to do the 
task that postgresql can do for you.

Perhaps plphp ? (since you know php)

# Here is an example plphp function.


   $txt = str_replace("\n","<br>\n",$arg0);

   if ($txt) {

     return $txt;


   else {

     return $arg0;


' LANGUAGE 'plphp';

Then on a select, I'd run

SELECT id, line_breaks(textbox_field) as textbox_field FROM table;

It would then replace all instances of \n with <br>\n.



Robby Russell,  |  Sr. Administrator / Lead Programmer
Command Prompt, Inc.   |
rrussell(at)commandprompt(dot)com | Telephone: (503) 222.2783

In response to

pgsql-php by date

Next:From: StephenDate: 2003-10-21 05:58:24
Subject: Support for prepared queries
Previous:From: Rod KDate: 2003-10-13 02:36:55
Subject: Re: newlines won't display in browser

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group