Extract value of inputs from a HTML document using PHP

     

I have 347 .htm files saved in a folder. Each file contains an HTML form (same structure in every file). Assume the HTML form in each file will have something like:


    
  

I Managed to create a loop to get content of every file in the folder:


Foreach($filesText as $fileName=>$fileText){   // I need help to search in the text for the value of each input   //So I want to fillup this array
$filesArray[$fileName]['fhname'] = $fname;   $filesArray[$fileName]['shname'] = $shname;   $filesArray[$fileName]['age'] = $age;  }  

I need help to search in the text for the value of each variable so:


      
  • $fname => will be the value of input with ID fname
  •   
  • $shname => will be the value of input with ID shname
  •   
  • $age => will be the value of select with ID age and so on...
  •   
  
"
answer1
  
  

see PHP DOMDocument: How do I get the value of an input field and http://php.net/manual/en/book.dom.php


$html = <<    test        
      EOD;
$dom = new DOMDocument;  $dom->loadHTML($html);  $fhname = $dom->getElementById('fhname');  print $fhname->getAttribute('value');
=> Moe  

This should get you pointed in the right direction.