Обсуждение: Printing off the page....

Поиск
Список
Период
Сортировка

Printing off the page....

От
SG Edwards
Дата:
Hi guys,

I have a postgres database connected to a website using PHP.
I have a table that stores gene sequences which are very long (approx. 800
characters).

If I try and print this, it prints as a single line which runs off the page. Is
there a way to print the sequence with a line break every 50 characters?

for example,

AAAAAAAAAAAACCCCCCCCCCC
TTTTTTTTTTTTTTTTGGGGGGG
AAAAAAAAATTT


Rather than:

AAAAAAAAAAACCCCCCCCCCCCTTTTTTTTTTTTTGGGGGGGGGGGAAAAAAAAAATTT

Re: Printing off the page....

От
David Blanco
Дата:
Hi!

2005/5/13, SG Edwards <s0460205@sms.ed.ac.uk>:
>
> Hi guys,
>
> I have a postgres database connected to a website using PHP.
> I have a table that stores gene sequences which are very long (approx. 800
> characters).
>
> If I try and print this, it prints as a single line which runs off the page. Is
> there a way to print the sequence with a line break every 50 characters?

This seems to be a PHP question, not about PHP-Posgresql :-)

If I understood you right, you can do it with the PHP function "substr"

http://php.net/substr

It's easy to iterate throug the string and to intercalate the line
breaks wherever you want

Bye

Re: Printing off the page....

От
Volkan YAZICI
Дата:
Hi,

On 5/13/05, SG Edwards <s0460205@sms.ed.ac.uk> wrote:
> I have a postgres database connected to a website using PHP.
> I have a table that stores gene sequences which are very long (approx. 800
> characters).
>
> If I try and print this, it prints as a single line which runs off the page. Is
> there a way to print the sequence with a line break every 50 characters?
>
> for example,
>
> AAAAAAAAAAAACCCCCCCCCCC
> TTTTTTTTTTTTTTTTGGGGGGG
> AAAAAAAAATTT
>
> Rather than:
> AAAAAAAAAAACCCCCCCCCCCCTTTTTTTTTTTTTGGGGGGGGGGGAAAAAAAAAATTT

You can write a simple wrap function for it. For example:

function wrapAndPrint($text, $maxLineLen = 50)
{
    // We don't need to make a strlen() call everytime.
    $lineLen = strlen($text);

    for ( $i = 0; $i < $lineLen; $i++ )
        print $text[$i].(( $i % $maxLineLen == 0 ) ? '\n' : '');
}

And then you can call wrapAndPrint() function everytime, when you need
to print fetched rows from the query result.

(Also it's possible to write a PL/WHATEVER function for it too.)

Regards.

Re: Printing off the page....

От
Volkan YAZICI
Дата:
Oops. I forgot some other built-in PHP functions.

I think it's more feasible to use chunk_split(). (You can take a look
at wordwrap() function too but I'd advice chunk_split(). Also
chunk_split() should work much faster than any other function we wrote
by using PHP.)

Regards.

Re: Printing off the page....

От
Christopher Kings-Lynne
Дата:
Use the PHP wordwrap() function.

SG Edwards wrote:
> Hi guys,
>
> I have a postgres database connected to a website using PHP.
> I have a table that stores gene sequences which are very long (approx. 800
> characters).
>
> If I try and print this, it prints as a single line which runs off the page. Is
> there a way to print the sequence with a line break every 50 characters?
>
> for example,
>
> AAAAAAAAAAAACCCCCCCCCCC
> TTTTTTTTTTTTTTTTGGGGGGG
> AAAAAAAAATTT
>
>
> Rather than:
>
> AAAAAAAAAAACCCCCCCCCCCCTTTTTTTTTTTTTGGGGGGGGGGGAAAAAAAAAATTT
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org