php - Variable variables in SimpleXMLElement -
i have 'simple' problem :-)
i'm reading large xml file using this:
$node = new simplexmlelement($reader->readouterxml());
$node have elements severity, class... can compare them this:
if($node->severity==warning){
or show them this:
echo $node->severity;
what want prepare if statements in advance reading posts variables this:
if(isset($_post['severity']) && !empty($_post['severity'])){ $severity[]=$_post['severity']; foreach($severity $severityval){ foreach($severityval $severityvalues){ $searchquery .= '($node->severity==' .$severityvalues. ') || '; } } }
then want use $searchquery inside xml reader:
if($searchquery){ echo $node->severity; }
but, return true , shown :-(
my variable created, if echo shows ($node->severity==warning)
maybe screen shot can explain problem:
thanks in advance
try :
if(isset($_post['severity']) && !empty($_post['severity'])) { $severity[] = $_post['severity']; $i = 0; foreach($severity $severityval) { foreach($severityval $severityvalues) { if ($node->severity == $severityvalues) { $i++; } } } if ($i > 0) { echo $node->severity; } }
edit : understand problematic, if had loaded 1 per 1 xml, can (for each selected on node value - example work severity, it's sample) :
$root_node = $your_var; if(isset($_post['severity']) && strlen(trim($_post['severity'])) > 0) { $severities_selected = array_values($_post['severity']); $severity = (string) $root_node->severity; if (in_array($severity, $severities_selected)) { echo "this xml contains 1 selected severity (".$severity.")"; } }
hope helps !!
Comments
Post a Comment