I use simplehtmldom (http://sourceforge.net/projects/simplehtmldom/) and the following code to sanitize user input ($ticket_text, removing things like onclick, onkeydown, etc.):
$dom=str_get_html($ticket_text);
foreach ($dom->find('*') as $elem) {
foreach ($elem->getAllAttributes() as $attr => $val) {
$elem->removeAttribute($attr);
}
if ($elem->hasChildNodes()) {
foreach ($elem->childNodes as $childNode){
foreach ($childNode->getAllAttributes() as $attr => $val) {
$childNode->removeAttribute($attr);
}
}
}
}
Now I receive the following warning in my error_log for the line containing foreach ($elem->childNodes as $childNode){
:
WARNING [2] foreach() argument must be of type array|object, bool given
I don’t understand how this can happen. If I do a check with “hasChildNodes()” how can $elem->childNodes
yield a boolean?