我是 codeigniter 的新手。我得到 html 字符串形式数据库,如下所示<div class="rockfm-form-container uiform-wrap"><div class="rockfm-alert-container"></div><form class="rockfm-form" action="" name="" method="post" data-zgfm-type="1" enctype="multipart/form-data" id="rockfm_form_7"><input type="hidden" value="7" class="_rockfm_form_id" name="_rockfm_form_id"> <input type="hidden" value="0" class="_rockfm_wizard_st" > <input type="hidden" value="PGRpdiBjbGFzcz0icm9ja2ZtLWFsZXJ0IHJvY2tmbS1hbGVydC1zdWNjZXNzIj5TdWNjZXNzISBGb3JtIHdhcyBzZW50IHN1Y2Nlc3NmdWxseS48L2Rpdj4=" name="_rockfm_onsubm_smsg" class="_rockfm_onsubm_smsg" > <!--- ajax or post ---> <input type="hidden" value="1" class="_rockfm_type_submit" name="_rockfm_type_submit"> <input type="hidden" value="rocket_front_submitajaxmode" name="action"> <div class="uiform-main-form"> <div class="uiform-step-content" > <div id="rockfm_uiibpy0eewu" data-idfield="uiibpy0eewu" data-typefield="33" class="rockfm-heading rockfm-field " ></div> <div id="rockfm_uiya0wevyae" data-idfield="uiya0wevyae" data-typefield="28" class="rockfm-preptext rockfm-field rockfm-required " data-val-type="4"></div> <div id="rockfm_ui04fxilqp6" data-idfield="ui04fxilqp6" data-typefield="7" class="rockfm-textarea rockfm-field " ></div> <div id="rockfm_uiwdtl19w05" data-idfield="uiwdtl19w05" data-typefield="10" class="rockfm-select rockfm-field " ></div> <div id="rockfm_uiksx46ggj9" data-idfield="uiksx46ggj9" data-typefield="12" class="rockfm-fileupload rockfm-field " ></div> </div></div></form></div>我有另一个类型字段表,如图所示问题是,当typefield = 10 且 flag_status = 0时,它会被删除<div id="rockfm_uiwdtl19w05" data-idfield="uiwdtl19w05" data-typefield="10" class="rockfm-select rockfm-field " ></div>,但 html 字符串中的其他信息也会被删除。我展示了控制器函数的代码,其中我将 html 字符串转换为 DOM 文档,获取fby_id和flag_status表单类型字段表的记录,并创建该记录的数组。然后使用 DOM 查询对 data-typefield 进行 foreach 循环以获取 data-typefield 的属性值,然后添加 if 0 = 1 的检查条件,然后删除特定的 div
1 回答
梵蒂冈之花
TA贡献1900条经验 获得超5个赞
您的代码大部分都在那里,但主要部分是删除节点,我已更改测试以判断状态是否= 0,然后用于removeChild()删除该元素。那么文档<div>末尾应该只包含您想要的元素......
foreach ($xpath->query("//div[@data-typefield]") as $item)
{
$typefield = $item->getAttribute('data-typefield');
if($field_array[$typefield] == 0)
{
$item->parentNode->removeChild($item);
}
}
echo $doc->saveHTML();
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
0/150
提交
取消