Home > Archive > PHP with PostgreSQL > May 2005 > Printing off the page....









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Printing off the page....
SG Edwards

2005-05-13, 7:23 am


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,

AAAAAAAAAAAACCCCCCCC
CCC
TTTTTTTTTTTTTTTTGGGG
GGG
AAAAAAAAATTT


Rather than:

AAAAAAAAAAACCCCCCCCC
CCCTTTTTTTTTTTTTGGGG
GGGGGGGAAAAAAAAAATTT


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql
.org

David Blanco

2005-05-13, 7:23 am

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

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Volkan YAZICI

2005-05-13, 7:23 am

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,
>
> AAAAAAAAAAAACCCCCCCC
CCC
> TTTTTTTTTTTTTTTTGGGG
GGG
> AAAAAAAAATTT
>
> Rather than:
> AAAAAAAAAAACCCCCCCCC
CCCTTTTTTTTTTTTTGGGG
GGGGGGGAAAAAAAAAATTT


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.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Volkan YAZICI

2005-05-13, 7:23 am

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.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Christopher Kings-Lynne

2005-05-14, 7:23 am

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,
>
> AAAAAAAAAAAACCCCCCCC
CCC
> TTTTTTTTTTTTTTTTGGGG
GGG
> AAAAAAAAATTT
>
>
> Rather than:
>
> AAAAAAAAAAACCCCCCCCC
CCCTTTTTTTTTTTTTGGGG
GGGGGGGAAAAAAAAAATTT

>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql
.org


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com