Thursday, October 29, 2009

PDF : Solution for replace the \r to \n into multicell()



How can we retrieved the data from database and perform as WYSWYG in the pdf format.
As we know that MultiCell(float w, float h, string txt [, mixed border [, string align [, int fill]]]) is a method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.


Text can be aligned, centered or justified. The cell block can be framed and the background painted.

But, for the pdf class to know the break line only when it meet the '\n' in the string. If let's said the string is include the '\r' ? It doesn't work.

The Solution is we need to replace the '\r' to become a '\n'.

example :
$myString = str_replace('\\r','\n',mysql_real_escape_string($databaseResult));
$pdf->MultiCell(0,4,$myString,0,0,0);

mysql_real_escape_string — Escapes special characters in a string for use in a SQL statement

this info from Charlie,thanks:

No comments:

Post a Comment

Your comments is appreciate.