Re: newlines won't display in browser

Поиск
Список
Период
Сортировка
От Robby Russell
Тема Re: newlines won't display in browser
Дата
Msg-id 3F8AB84E.8030008@commandprompt.com
обсуждение исходный текст
Ответ на newlines won't display in browser  (Michael Hanna <taojones@sympatico.ca>)
Список 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)

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


В списке pgsql-php по дате отправления:

Предыдущее
От: "Rod K"
Дата:
Сообщение: Re: newlines won't display in browser
Следующее
От: ljb
Дата:
Сообщение: Re: Support for prepared queries