php函数将描述拆分为68个字符长的行

php函数将描述拆分为68个字符长的行,php,pdf,Php,Pdf,我只是想知道是否有人能帮我。我一整天都在想这个问题。 我有这些变量 $booking['occasion'] $booking['date'] $booking['venue'] 我想这样描述它们 $description=“为现场$sition提供DJ的押金 $VICE中的$date” 我想在pdf文件中显示3或4行以上的描述,如下所示 $pdf->writeHTMLCell(139, 5, '20', '125', $line1, '', 1, 1, true, 'L', true)

我只是想知道是否有人能帮我。我一整天都在想这个问题。 我有这些变量

$booking['occasion']
$booking['date']
$booking['venue']
我想这样描述它们

$description=“为现场$sition提供DJ的押金 $VICE中的$date”

我想在pdf文件中显示3或4行以上的描述,如下所示

$pdf->writeHTMLCell(139, 5, '20', '125', $line1, '', 1, 1, true, 'L', true);
$pdf->writeHTMLCell(139, 5, '25', '125', $line2, '', 1, 1, true, 'L', true);
$pdf->writeHTMLCell(139, 5, '30', '125', $line3, '', 1, 1, true, 'L', true);
$pdf->writeHTMLCell(139, 5, '35', '125', $line4, '', 1, 1, true, 'L', true);
$pdf->writeHTMLCell(139, 5, '40', '125', $line5, '', 1, 1, true, 'L', true);
我想在每68个字符后将描述换行,但只想在完成的单词后换行

有人能帮我创建一个函数,将设计拆分成3或4行吗?到目前为止,我有这个代码,我知道它符合我的要求

$description = "Deposit for suppling a DJ and Equipment for a $occasion on the 
$date in $venue";
$decriptionLength = strlen($description);
if($decriptionLength <= 68){
  $line1 = $description;    
}
elseif($decriptionLength > 68)
{
  $line1 = substr($description, 0, 68);
  $line2 = substr($description, 68, 136);
}
$description=“在现场为$sition提供DJ和设备的押金
$VICENT中的$date”;
$descriptionLength=strlen($description);
如果($decriptionLength 68)
{
$line1=substr($description,0,68);
$line2=substr($description,68136);
}
<>这个代码会把文本包在一个单词的中间,所以我不想要这个。 我知道这可能是一个很大的要求,但如果有人能拿出一些代码,我将不胜感激

函数
wordwrap()
可能会有所帮助

$wordwrapp=wordwrapp($description,139,“\n”);
$lines=explode(“\n”,$wordwrapped);
$line1=$lines[0];
$line2=$lines[1];
如果(计数($line)>3){
$third_line=“”;
对于($idx=1;$idx
您试过了吗?谢谢您的帮助。我在第二行“警告:内爆()[函数.内爆]:传递的参数无效”中遇到错误。有什么想法吗?
$wordwrapped = wordwrap($description, 139, "\n");

$lines = explode("\n", $wordwrapped);

$line1 = $lines[0];
$line2 = $lines[1];

if (count($lines) > 3) {

    $third_line = "";

    for ($idx = 1; $idx < count($lines); $idx++) {
        $third_line .= $lines[$idx] . " ";
    }

    $line3 = $third_line;

}

else {

    $line3 = $lines[2];

}