fork download
  1. <?php
  2.  
  3. $html = <<<DATA
  4. <select id="current-statement" name="current-statement" data-reactid=".4.2.2.1.0.2.1.1.0">
  5. <option value="current" data-reactid=".4.2.2.1.0.2.1.1.0.0">Current Statement</option>
  6. <option value="90989266-c853-289b-dfea-3cdfe2213db7" data-reactid=".4.2.2.1.0.2.1.1.0.1">1st Statement</option>
  7. <option value="165eb5ea-fd48-53c8-020b-6e3287859922" data-reactid=".4.2.2.1.0.2.1.1.0.2">second statement</option>
  8. <option value="0d558fa0-8f48-afa2-7a9a-e8f85fbbbc42" data-reactid=".4.2.2.1.0.2.1.1.0.3">third statement</option>
  9. <option value="9c78f8aa-3b09-4574-1c10-8f450b45eb5b" data-reactid=".2.0.0.1.0.2.1.1.0.4">4th statement</option>
  10. </select>
  11. DATA;
  12.  
  13. $dom = new DOMDocument('1.0', 'UTF-8');
  14. $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  15.  
  16. $xpath = new DOMXPath($dom);
  17. $opts = $xpath->query('//select/*/text()');
  18. $res = array();
  19. foreach($opts as $opt) {
  20. array_push($res, $opt->nodeValue);
  21. }
  22. print_r($res);
  23.  
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Current Statement
    [1] => 1st Statement
    [2] => second statement
    [3] => third statement
    [4] => 4th statement
)