将标签输入数组后剥离标签?

时间:2018-06-21 14:27:15

标签: php

如何剥离单个物品的标签?使用当前的设置,我最后得到一个长字符串,表明所有标签均已剥离。

如何将$title输入到$value数组中,然后为其剥离标签?

// Product Codes
$contents = $html->find('div[class=product-table]', 0);
$contents = $contents->find('tr');
$counter = 1;
$value = array();
foreach ($contents as $item) {
  $field_key = "field_5ae0882f9d6f9";
  $title = strip_tags($item);
  $value[] = array(
    "column_title" => $title,
  );
  $counter++;
  break;
}
update_field( $field_key, $value, $post_id );

这是原始表,我想将每个表标题添加为一个单独的项目,剥离标签,然后使用update_field函数通过“高级自定义字段”插件将它们推入Wordpress。

enter image description here

2 个答案:

答案 0 :(得分:1)

这是您要寻找的吗?

// Product Codes
$contents = $html->find('div[class=product-table]', 0);
$contents = $contents->find('tr', 0)->find('td');
$counter = 1;
$value = array();
foreach ($contents as $item) {
  $field_key = "field_5ae0882f9d6f9";
  $value[] = array(
    "column_title" => "<td>" . strip_tags($item) . "</td>",
  );
  $counter++;
}
var_dump($value);
update_field( $field_key, $value, $post_id );

答案 1 :(得分:0)

// Product Codes
$contents = $html->find('div[class=product-table]', 0);
$contents = $contents->find('tr');
$counter = 1;
$value = array();
$i=0;

foreach ($contents as $tr) {
    if($i==0){
        foreach($tr->find('td') as $item) {
            $field_key = "field_5ae0882f9d6f9";
            $title = strip_tags($item);
            $value[] = array(
                 "column_title" => $title,
            );
            $counter++;
        }
    }
    $i++;

}
update_field( $field_key, $value, $post_id );

更改了它以遍历tr,限制为一个。应该遍历该行的所有td。