3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str=<<<XML <database name="newsportal"> <table name="wp_options"> <column name="option_id">1</column> <column name="option_name">siteurl</column> <column name="option_value">http://localhost/newsportal</column> <column name="autoload">yes</column> </table> <table name="wp_options"> <column name="option_id">2</column> <column name="option_name">home</column> <column name="option_value">http://localhost/newsportal</column> <column name="autoload">yes</column> </table> <table name="wp_options"> <column name="option_id">3</column> <column name="option_name">blogname</column> <column name="option_value">News Portal</column> <column name="autoload">yes</column> </table> <table name="wp_options"> <column name="option_id">4</column> <column name="option_name">blogdescription</column> <column name="option_value">Just another WordPress site</column> <column name="autoload">yes</column> </table> </database> XML; $xml=simplexml_load_string($str); $nodes = $xml->xpath("//database//table[@name='wp_options']"); foreach($nodes as $item) { $row = simplexml_load_string($item->asXML()); $v = $row->xpath("//column[@name='option_id'][.=('1','2','3')]"); if(count($v) > 0) { foreach($item->column as $column) { echo $column['name'] . '=' . $column . "<br/>"; } //echo $item->column['name']."<br/>"; } }
based on YnC31
Output for 7.2.0
Warning: SimpleXMLElement::xpath(): Invalid expression in /in/e4Jd3 on line 37 Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /in/e4Jd3 on line 37 Warning: count(): Parameter must be an array or an object that implements Countable in /in/e4Jd3 on line 39 option_id=1<br/>option_name=siteurl<br/>option_value=http://localhost/newsportal<br/>autoload=yes<br/> Warning: SimpleXMLElement::xpath(): Invalid expression in /in/e4Jd3 on line 37 Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /in/e4Jd3 on line 37 Warning: count(): Parameter must be an array or an object that implements Countable in /in/e4Jd3 on line 39 option_id=2<br/>option_name=home<br/>option_value=http://localhost/newsportal<br/>autoload=yes<br/> Warning: SimpleXMLElement::xpath(): Invalid expression in /in/e4Jd3 on line 37 Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /in/e4Jd3 on line 37 Warning: count(): Parameter must be an array or an object that implements Countable in /in/e4Jd3 on line 39 option_id=3<br/>option_name=blogname<br/>option_value=News Portal<br/>autoload=yes<br/> Warning: SimpleXMLElement::xpath(): Invalid expression in /in/e4Jd3 on line 37 Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /in/e4Jd3 on line 37 Warning: count(): Parameter must be an array or an object that implements Countable in /in/e4Jd3 on line 39 option_id=4<br/>option_name=blogdescription<br/>option_value=Just another WordPress site<br/>autoload=yes<br/>
Output for 5.3.21 - 7.1.10
Warning: SimpleXMLElement::xpath(): Invalid expression in /in/e4Jd3 on line 37 Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /in/e4Jd3 on line 37 option_id=1<br/>option_name=siteurl<br/>option_value=http://localhost/newsportal<br/>autoload=yes<br/> Warning: SimpleXMLElement::xpath(): Invalid expression in /in/e4Jd3 on line 37 Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /in/e4Jd3 on line 37 option_id=2<br/>option_name=home<br/>option_value=http://localhost/newsportal<br/>autoload=yes<br/> Warning: SimpleXMLElement::xpath(): Invalid expression in /in/e4Jd3 on line 37 Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /in/e4Jd3 on line 37 option_id=3<br/>option_name=blogname<br/>option_value=News Portal<br/>autoload=yes<br/> Warning: SimpleXMLElement::xpath(): Invalid expression in /in/e4Jd3 on line 37 Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /in/e4Jd3 on line 37 option_id=4<br/>option_name=blogdescription<br/>option_value=Just another WordPress site<br/>autoload=yes<br/>