Jump to content


Photo

\n issue in php


  • Please log in to reply
16 replies to this topic

#1 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 01 September 2006 - 06:41 AM

i am working on how to create PDFs through PHP by importing the ezpdf class.  the inserting of text in the PDF file works fine but the \n character is ignored thus making the text overlap each other.  However, in some machines it works out fine and the \n character is applied.  So i was just wondering if you are familiar with this problem? is this something to do with the configuration of the php (php.ini)?

For example (coming from PHP):

$pdf->ezText("hello\nagain", 12);

the ideal display or output is:
hello
again

but instead of displaying it, it ignores the \n character making the text overlap each other.

hope someone could help me out with this, thanks in advance :)


#2 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 01 September 2006 - 06:45 AM

Try the function nl2br();??

#3 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 01 September 2006 - 06:54 AM

already tried it but the "br" tag is written on the pdf as well. i'm guessing that it is with the configuration of PHP in each of the machines but not sure what it is should be changed in the configuration file

#4 logu

logu
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 01 September 2006 - 07:05 AM

try \r\n instead of \n

#5 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 01 September 2006 - 07:14 AM

i just tried itl but no change still both \r\n are ignored and when br tag is used or inserted, it is also displayed or written on the PDF file. 

can this issue be resolved in php.ini file?

thanks

#6 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 01 September 2006 - 07:58 AM

you might have magic_quotes_runtime() on, or if you aren't passing the value directly (i.e. from a form and in a variable) you may need to strip magic_quotes_gpc()

#7 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 01 September 2006 - 08:04 AM

this is your best go
<?php
echo nl2br("hello
welcome
bye");?>

the out but into html should be somthing like this
hello<br>
welcome<br>
bye


:D

#8 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 01 September 2006 - 08:41 AM

thanks for all the quick reply

when i checked my php.ini file, the setup is already
magic_quotes_gpc() = On
magic_quotes_runtime() = Off
magic_quotes_sybase() = Off


i cannot figure out what is wrong anymore?


#9 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 01 September 2006 - 09:22 AM

where is the value coming from? Are you inputting explicitly as per your example, or is the data coming from say the $_POST superglobal?

#10 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 01 September 2006 - 09:46 AM

actually i am retrieving details from the database then i would store it on a variable

let's say i would retrieve an id and name from the database and combine them into one string

$string=id ."\n". name;

after which i would use the string variable to write on the pdf using

$pdf->ezText($string, 7);

but after this process and when the pdf is streamed into php, the id and name overlap each other instead of the name placed on the next line on the pdf file created.

i am running out of ideas because this same code when run in another server (with the same configuration and setup) actually works, meaning the id and name are separated and the newline character was applied.



#11 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 01 September 2006 - 10:20 AM

Which class are you using for $pdf?

#12 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 September 2006 - 12:55 AM

the classes that i used are class.ezpdf.php and class.pdf.php, wherein the class ezpdf extends the latter class.  both classes are version 9 and were downloaded from the net

just to reiterate, the confusing part here is that why in some machines it work but in others it doesn't

thanks for all the replies



#13 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 04 September 2006 - 01:13 AM

try swapping to \r\n, and if still problematic try with just \r.

#14 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 September 2006 - 01:33 AM

still no luck, if \r\n is used the text overlaps

but when \r alone is used it just writes/displays the text in one line.

my guess is that the problem is already with the configuration or settings because the same scripts are used in different machines though not all display the desired appearance of the text on the PDF.  of course, i'm still new with the ezpdf functionality.

any other ideas will be greatly appreciated  :)

#15 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 04 September 2006 - 01:38 AM

check encoding too, at a guess ezpdf will need UTF-8 - finding any docs for eZ is a pain so I can't verify.

#16 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 September 2006 - 01:40 AM

thanks, i'm already looking for a decent documentation on the ezpdf class

#17 atchua

atchua
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 06 September 2006 - 01:11 AM

i haven't found any descent documentation about ezPDF and if there are there were no details about special characters. 


i already tried using nl2br() and addslashes() but neither works.  the first one makes the system also display the br tag while the latter has no effect to the string displayed meaning it has the same effect of text being overlapped to each other.

any other ideas as to why this is so? cannot figure out what to do anymore

thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users