pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Printing off the page....
5+ messages / 4 participants
[nested] [flat]

* Printing off the page....
@ 2005-05-13 09:55 SG Edwards <s0460205@sms.ed.ac.uk>
  2005-05-13 11:49 ` Re: Printing off the page.... David Blanco <dablanco@gmail.com>
  2005-05-13 11:58 ` Re: Printing off the page.... Volkan YAZICI <volkan.yazici@gmail.com>
  2005-05-14 09:02 ` Re: Printing off the page.... Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 3 replies; 5+ messages in thread

From: SG Edwards @ 2005-05-13 09:55 UTC (permalink / raw)
  To: pgsql-php


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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Printing off the page....
  2005-05-13 09:55 Printing off the page.... SG Edwards <s0460205@sms.ed.ac.uk>
@ 2005-05-13 11:49 ` David Blanco <dablanco@gmail.com>
  2 siblings, 0 replies; 5+ messages in thread

From: David Blanco @ 2005-05-13 11:49 UTC (permalink / raw)
  To: pgsql-php

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Printing off the page....
  2005-05-13 09:55 Printing off the page.... SG Edwards <s0460205@sms.ed.ac.uk>
@ 2005-05-13 11:58 ` Volkan YAZICI <volkan.yazici@gmail.com>
  2005-05-13 12:03   ` Re: Printing off the page.... Volkan YAZICI <volkan.yazici@gmail.com>
  2 siblings, 1 reply; 5+ messages in thread

From: Volkan YAZICI @ 2005-05-13 11:58 UTC (permalink / raw)
  To: SG Edwards <s0460205@sms.ed.ac.uk>; +Cc: 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.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Printing off the page....
  2005-05-13 09:55 Printing off the page.... SG Edwards <s0460205@sms.ed.ac.uk>
  2005-05-13 11:58 ` Re: Printing off the page.... Volkan YAZICI <volkan.yazici@gmail.com>
@ 2005-05-13 12:03   ` Volkan YAZICI <volkan.yazici@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Volkan YAZICI @ 2005-05-13 12:03 UTC (permalink / raw)
  To: pgsql-php

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.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Printing off the page....
  2005-05-13 09:55 Printing off the page.... SG Edwards <s0460205@sms.ed.ac.uk>
@ 2005-05-14 09:02 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2 siblings, 0 replies; 5+ messages in thread

From: Christopher Kings-Lynne @ 2005-05-14 09:02 UTC (permalink / raw)
  To: SG Edwards <s0460205@sms.ed.ac.uk>; +Cc: pgsql-php

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2005-05-14 09:02 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-05-13 09:55 Printing off the page.... SG Edwards <s0460205@sms.ed.ac.uk>
2005-05-13 11:49 ` David Blanco <dablanco@gmail.com>
2005-05-13 11:58 ` Volkan YAZICI <volkan.yazici@gmail.com>
2005-05-13 12:03   ` Volkan YAZICI <volkan.yazici@gmail.com>
2005-05-14 09:02 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>

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