Jump to content

Need help with domDocument @ <select> tags


physaux

Recommended Posts

	$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)?  :confused:

Link to comment
https://forums.phpfreaks.com/topic/189204-need-help-with-domdocument-tags/
Share on other sites

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: :confused: :wtf::shrug:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.