Search code examples
phpsimple-html-dom

Count form inputs using PHP Simple HTML DOM


I am attempting to look though the code for forms containing more than 3 input fields. I cant seem to find a function to count only the inputs within a form tag without knowing the form id or class. I have created the following code below to collect and loop through each form.

$forms = $this->html->find('form');
if(count($forms)>0){
    foreach($forms as $form){

    }
}

I have looked into the using $form->children() to count the children. The issue is I would have to continue to look into childrens children to look for inputs. Are there any other methods that would speed up counting the inputs within each form?


Solution

  • It would look something like this:

    $forms = $this->html->find('form');
    foreach($forms as $form){
      if(count($form->find('input')) > 3) echo "Found one!";
    }