Php 使用FPDF限制字符串的字符数
我试图用FPDF在PDF文档上显示一些数据,我的问题是我不能限制字符串的字符数,有时宽度超过,我已经使用了MultiCell,但我不想设置字符数限制 我试图用我的函数custom echo解决这个问题,但显然不能用fpdf解决,我不知道会发生什么Php 使用FPDF限制字符串的字符数,php,fpdf,Php,Fpdf,我试图用FPDF在PDF文档上显示一些数据,我的问题是我不能限制字符串的字符数,有时宽度超过,我已经使用了MultiCell,但我不想设置字符数限制 我试图用我的函数custom echo解决这个问题,但显然不能用fpdf解决,我不知道会发生什么 function custom_echo($x, $length) { if(strlen($x)<=$length) { echo $x; } else { $y=subs
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);
// already tried this
$pdf->MultiCell( 95, 6, custom_echo(utf8_decode($message),5), 0, 1);
$pdf->Output();
函数自定义_echo($x,$length)
{
if(strlen($x)SetLeftMargin(0);
$pdf->AddPage();
$pdf->MultiCell(95,6,utf8解码(自定义回波($message,5)),0,1);
//已经试过了
$pdf->MultiCell(95,6,自定义回波(utf8\U解码($message),5),0,1);
$pdf->Output();
你看过文档了吗?这里有一个有趣的例子。
您可以创建一个类FPDF_CellFit并创建该类的对象。
请参见此url中的示例
希望这有帮助。PHP
echo
命令将字符串发送到输出。您需要将字符串作为函数的结果返回,以便FPDF可以使用它
function custom_echo($x, $length) {
if (strlen($x) <= $length) {
return $x;
} else {
return substr($x,0,$length) . '...';
}
}
函数自定义_echo($x,$length){
如果(斯特伦($x)我不能相信那个错误,谢谢你抽出时间!!@edgarreyes我也犯过这样的错误。
function custom_echo($x, $length) {
if (strlen($x) <= $length) {
return $x;
}
return substr($x,0,$length) . '...';
}