Re: Printing off the page.... - Mailing list pgsql-php

From Volkan YAZICI
Subject Re: Printing off the page....
Date
Msg-id 7104a73705051304583d38f3ee@mail.gmail.com
Whole thread Raw
In response to Printing off the page....  (SG Edwards <s0460205@sms.ed.ac.uk>)
Responses Re: Printing off the page....
List pgsql-php
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.

pgsql-php by date:

Previous
From: David Blanco
Date:
Subject: Re: Printing off the page....
Next
From: Volkan YAZICI
Date:
Subject: Re: Printing off the page....