physaux Posted January 20, 2010 Share Posted January 20, 2010 $dom = new DOMDocument; libxml_use_internal_errors(true); @$dom->loadHTML($pagedata); libxml_use_internal_errors(false); $xpath = new DOMXPath($dom); $aTag = $xpath->query('//select'); $finaloutput = array(); foreach($aTag as $thisform){ $selectname = $thisform->getAttribute('name'); $selectvalue = $thisform->nodeValue; $finaloutput[] = array( 'name' => $selectname, 'value' => $selectvalue ); } return $finaloutput; That is my code so far. But I need to get more of the data. Here is a sample of $pagedata <select name="m_field_id_1" class="select"><option value="Yes">Yes</option><option value="No">No</option></select> <select name="m_field_id_2" class="select"><option value="Yes">Yes</option><option value="No">No</option></select> How can I select what I have already, as well as the "inner" option tags(and their nodevalue's and names)? Link to comment https://forums.phpfreaks.com/topic/189204-need-help-with-domdocument-tags/ Share on other sites More sharing options...
physaux Posted January 20, 2010 Author Share Posted January 20, 2010 Ok guys, I have updated my code so far, but I am getting many errors... $dom = new DOMDocument; libxml_use_internal_errors(true); @$dom->loadHTML($pagedata); libxml_use_internal_errors(false); $xpath = new DOMXPath($dom); $aTag = $xpath->query('//select'); $finaloutput = array(); foreach($aTag as $thisform){ $selectname = $thisform->getAttribute('name'); $themchilds = $thisform->child_nodes; //THIS IS LINE 16 $childarray = array(); $finaloutput[] = array('name' => $selectname); $tempnum = count($finaloutput)-1; foreach($themchilds as $themchild){ //THIS IS LINE 20 $tempvalue= $themchild->getAttribute('value'); $tempnode= $themchild->nodeValue; $finaloutput[$tempnum][] = array(); $tempnum2 = count($finaloutput[$tempnum])-1; $finaloutput[$tempnum][$tempnum2]['value'] = $tempvalue; $finaloutput[$tempnum][$tempnum2]['node'] = $tempnode; } } return $finaloutput; Here are the errors I got: :'( :'( :'( Notice: Undefined property: DOMElement::$child_nodes in /home/.../file.php on line 16 Warning: Invalid argument supplied for foreach() in /home/.../file.php on line 20 Notice: Undefined property: DOMElement::$child_nodes in /home/.../file.php on line 16 Warning: Invalid argument supplied for foreach() in /home/.../file.php on line 20 And once again, a sample of the html code I am using is here: <select name="m_field_id_1" class="select"><option value="Yes">Yes</option><option value="No">No</option></select> <select name="m_field_id_2" class="select"><option value="Yes">Yes</option><option value="No">No</option></select> Could anyone please help!! :confused: Link to comment https://forums.phpfreaks.com/topic/189204-need-help-with-domdocument-tags/#findComment-998938 Share on other sites More sharing options...
physaux Posted January 21, 2010 Author Share Posted January 21, 2010 *bump*.. anyone?? I still can't get it to work... :'( :'( :'( :'( :'( :'( :'( :'( :'( Link to comment https://forums.phpfreaks.com/topic/189204-need-help-with-domdocument-tags/#findComment-999104 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.