pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robby Russell <rrussell@commandprompt.com>
To: pgsql-php@postgresql.org
Subject: Re: newlines won't display in browser
Date: Mon, 13 Oct 2003 07:35:58 -0700
Message-ID: <3F8AB84E.8030008@commandprompt.com> (raw)
In-Reply-To: <2CCFF91A-FD21-11D7-A49D-00039308EB2C@sympatico.ca>
References: <2CCFF91A-FD21-11D7-A49D-00039308EB2C@sympatico.ca>

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)

https://www.commandprompt.com/entry.lxp?lxpe=294

# Here is an example plphp function.

CREATE OR REPLACE FUNCTION line_breaks(text) RETURNS text AS '

   $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.


Cheers,

Robby


-- 
Robby Russell,  |  Sr. Administrator / Lead Programmer
Command Prompt, Inc.   |  http://www.commandprompt.com
rrussell@commandprompt.com | Telephone: (503) 222.2783




view thread (3+ messages)

Message-ID: <3F8AB84E.8030008@commandprompt.com>
Permalink:  ../3F8AB84E.8030008@commandprompt.com/
Also on:    postgresql.org/message-id/3F8AB84E.8030008@commandprompt.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: rrussell@commandprompt.com
  Subject: Re: newlines won't display in browser
  In-Reply-To: <3F8AB84E.8030008@commandprompt.com>
  References: <2CCFF91A-FD21-11D7-A49D-00039308EB2C@sympatico.ca> <3F8AB84E.8030008@commandprompt.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox