我的字段包含列表<ul class = "..."> <li> <something class = "MY CLASS">
。我需要过滤结果,以便只有具有所需类的元素保留在列表中。我试过explode ('<li>', $array);
但是我总是返回“原始”列表。我只需要class=" cf_sel_opt"
的元素(在第一个列表<a>
标记中,在其他<label>
标记中)。
我做错了什么?
这是我的PHP代码
foreach ($filters_render_array['html'] as $key => $value) {
if (strpos($key, 'custom_f_') !== false) {
$search_class = "cf_sel_opt";
print_r($value);
}
}
返回此列表
<ul class="cf_filters_list cf_colorbtn_list" id="cf_list_custom_f_35_129">
<li>
<a href="#" class="cf_option cf_color_btn cf_sel_opt">
<span class="cf_color_inner" style="background-color:black; width:100%;">
</span>
</a>
<input name="custom_f_35[]" value="313038" type="hidden">
</li>
<li>
<a href="#" class="cf_option cf_color_btn">
<span class="cf_color_inner" style="background-color:pink; width:100%;">
</span>
</a>
</li>
<li>
<a href="#" class="cf_option cf_color_btn">
<span class="cf_color_inner" style="background-color:white; width:100%;">
</span>
</a>
</li>
</ul>
<ul class="cf_filters_list" id="cf_list_custom_f_36_129">
<li>
<label class="" for="custom_f_36_129_elid3139">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3139" value="3139" type="checkbox">
<a href="#">
7
</a>
</label>
</li>
<li>
<label class="" for="custom_f_36_129_elid3231">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3231" value="3231" type="checkbox">
<a href="#">
6
</a>
</label>
</li>
<li>
<label class="" for="custom_f_36_129_elid3232">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3232" value="3232" type="checkbox">
<a href="#">
5
</a>
</label>
</li>
<li>
<label class="" for="custom_f_36_129_elid3233">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3233" value="3233" type="checkbox">
<a href="#">
4
</a>
</label>
</li>
<li>
<label class="" for="custom_f_36_129_elid3334">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3334" value="3334" type="checkbox">
<a href="#">
3
</a>
</label>
</li>
<li>
<label class="" for="custom_f_36_129_elid3336">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3336" value="3336" type="checkbox">
<a href="#">
2
</a>
</label>
</li>
<li>
<label class="" for="custom_f_36_129_elid3338">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3338" value="3338" type="checkbox">
<a href="#">
2A
</a>
</label>
</li>
<li>
<label class=" cf_sel_opt" for="custom_f_36_129_elid3439">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3439" value="3439" checked="checked" type="checkbox">
<a href="#">
1
</a>
</label>
</li>
<li>
<label class=" cf_sel_opt" for="custom_f_36_129_elid3535">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3535" value="3535" checked="checked" type="checkbox">
<a href="#">
00
</a>
</label>
</li>
<li>
<label class=" cf_sel_opt" for="custom_f_36_129_elid3633">
<input name="custom_f_36[]" class="cf_flt" id="custom_f_36_129_elid3633" value="3633" checked="checked" type="checkbox">
<a href="#">
0
</a>
</label>
</li>
</ul>
<ul class="cf_filters_list" id="cf_list_custom_f_39_129">
<li>
<label class=" cf_sel_opt" for="custom_f_39_129_elid323332">
<input name="custom_f_39[]" class="cf_flt" id="custom_f_39_129_elid323332" value="323332" checked="checked" type="checkbox">
<a href="#">
Light/Mesh lycra
</a>
</label>
</li>
</ul>