我一直在嘗試在PHP中使用以下正則表達式打磚牆。轉換在PHP中使用正則表達式preg_replace
<li.*?class="(.*?gchoice.*?)">((.|\n)*?)<\/li>
這工作在下面的測試精細只選擇嵌套列表項時,我嘗試在一個基於jQuery測試
<li class="gfield gfield_contains_required" id="field_1_17">
<label class="gfield_label">Categories<span class="gfield_required"> (Required) </span> </label>
<div class="ginput_container">
<ul id="input_1_17" class="gfield_checkbox">
<li class="gchoice_17_1">
<input type="checkbox" id="choice_17_1" value="First Choice" name="input_17.1">
<label id="label_17_1" for="choice_17_1">First Choice</label>
</li>
</ul>
</div>
</li>
但是在PHP它只是不希望工作無論多麼我試圖逃避人物,無論我嘗試和使用的分隔符。據我所知,我應該只需要一個/或#在立場和結束,但是,當沒有工作,我試着逃避括號,但它仍然沒有工作。
您確定要使用正則表達式來解析HTML嗎? –