繁体   English   中英

php:在array_filter() 值之间插入换行符...?

[英]php: inserting line breaks between array_filter() values...?

我使用以下连接方法连接n潜在的“空”(零长度)字符串:

$joint_address = implode(",", array_filter([$joint_address_field_1, $joint_address_field_2, $joint_address_field_3, $joint_address_field_4, $joint_address_field_5, $joint_address_field_6]));

然后使用PDFM和其他类似功能将此变量发送到 PDF 表单字段。

然而,客户现在希望这个联合地址被换行。 如何准备此字符串为PDF字段换行?

我是否需要为具有长度的变量插入“\\r”回车符?

如何将它包含在 html 表中并将该 html 表存储在变量中

你必须把这种风格放在 pdf 视图中

  <style>
  .noborder{
        border:none;
  }
  .sticktogether{
       display: flow-root;
  }
  </style>

现在将 final_joint_address 变量发送到 pdf 视图

<?php
$joint_address_field_1 = "E/1/1 1-1";
$joint_address_field_2= "AAAAA 2";
$joint_address_field_3= "Near A B C";
$joint_address_field_4= "111111";
$joint_address_field_5= "C V B";
$joint_address_field_6= "VVVVVVVVV";


$joint_address = implode(",", array_filter([$joint_address_field_1, $joint_address_field_2, $joint_address_field_3, $joint_address_field_4, $joint_address_field_5, $joint_address_field_6]));

$addr_arr = explode(',',$joint_address);

$final_joint_address = "<table class='noborder'>";
$row = 0;
foreach($addr_arr as $key => $val )
{
    if($row == 0)
        $final_joint_address .= "<tr class='noborder sticktogether'>";

        $ifcomma =  $key == count($addr_arr) - 1 ? "":",";
        $final_joint_address .= "<td class='noborder'>$val $ifcomma</td>";

        if($row == 3 || $key ==(count($addr_arr) - 1)) //no of line breaks depends on "$row" value if $row = 3 will display 4 values seperated by commas as shown in results below in this case  
        {
            $final_joint_address .= "</tr>";
            $row = 0;
        }else
        {
            $row++;
        }

}
$final_joint_address .= "</table>";

echo $final_joint_address;
?>

//results : 
E/1/1 1-1 ,AAAAA 2 ,Near A B C ,111111 ,
C V B , VVVVVVVVV

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM