I have this check boxes that I need to get its checked values:
In this example, I would expect to get Ubuntu , because it is checked.
<div class="checkbox">
<label for="my_label_3-4">
<input id="my_label_3-4" type="checkbox" value="5" name="my_label_3[]" aria-invalid="false"></input>
Windows 7, 8
</label>
</div>
<div class="checkbox">
<label for="my_label_3-5">
<input id="my_label_3-5" type="checkbox" value="6" name="my_label_3[]" aria-invalid="false"></input>
Mac OS
</label>
</div>
<div class="checkbox">
<label for="my_label_3-6">
<input id="my_label_3-6" type="checkbox" checked="" value="7" name="my_label_3[]" aria-invalid="false"></input>
Ubuntu
</label>
</div>
<div class="checkbox">
<label for="my_label_3-7">
<input id="my_label_3-7" type="checkbox" value="8" name="my_label_3[]" aria-invalid="false"></input>
FreeBSD
</label>
</div>
How do I do so?
This is what I did so far, but hasn't return any result:
echo 'checkbox';
foreach ($html->find('my_label_3') as $id) {
echo $id; // returns 'checkbox'
}
Using Simple HTML Dom for parsing process
try using the label
to identify the nodes, as Ubuntu is not the value of the input
. It is the text of the label
, the value of that input
is 7.
foreach ($html->find('label[for^="my_label_3-"') as $label) {
if (!empty($label.find('input[checked]'))){
echo $label->innertext;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.