php - Limit the number of characters on a string with FPDF -
i'm trying display data on pdf document fpdf, problem can't limit number of characters of string , width exceeds, use multicell whant set limit of characters,
i tried solve function custom echo apparently doesn't work fpdf don't know happen.
function custom_echo($x, $length) { if(strlen($x)<=$length) { echo $x; } else { $y=substr($x,0,$length) . '...'; echo $y; } } $message= "hello world"; $pdf=new fpdf(); $pdf->setleftmargin(0); $pdf->addpage(); $pdf->multicell( 95, 6, utf8_decode(custom_echo($message,5)), 0, 1); // tried $pdf->multicell( 95, 6, custom_echo(utf8_decode($message),5), 0, 1); $pdf->output();
the php echo
command sends string output. need return string result of function fpdf can use it.
function custom_echo($x, $length) { if (strlen($x) <= $length) { return $x; } else { return substr($x,0,$length) . '...'; } }
which can simplified to:
function custom_echo($x, $length) { if (strlen($x) <= $length) { return $x; } return substr($x,0,$length) . '...'; }
and made shorter how it.
Comments
Post a Comment