We are using
The code examples for PHP XmlReader are as follows:
- < ? PHP
- Header ("content-type:text/html;
Charset=utf-8 ");
- $ URL = "http://www.google.com/
Ig/api?weather=shenzhen ";
- Loading XML content
- $ XML = New XMLReader ();
- $xml- > open ($url);
- $ condition = '' ;
- $ Temp_c = '' ;
- While ($xml->Read ()) {
- //Echo $xml- > name, "= = > ",
$xml->depth, "<br>";
- if (!empty ($condition)
&&!empty ($temp _c)) {
- Break
- }
- if ($xml->name = = ' condition '
&& empty ($condition)) {
- Take the first one condition
- $ condition = $xml- > getattribute (' data ');
- }
- if ($xml->name = = ' Temp_c ' &&
Empty ($temp _c)) {
- Take the first one Temp_c
- $ Temp_c = $xml- > getattribute (' data ');
- }
- $xml- > read ();
- }
- $xml- > close ();
- echo ' weather: ', $condition, ' < br />';
- Echo ' temp: ', $temp _c, ' < br />';
We just need to use PHP XmlReader to take the first condition and the first temp_c, so traverse all the nodes, will encounter the first condition and the first Temp_c write variable, the last output.
http://www.bkjia.com/PHPjc/446186.html www.bkjia.com true http://www.bkjia.com/PHPjc/446186.html techarticle The code examples we use in PHP XmlReader are as follows:? PHP header (content-type:text/html; Charset = Utf-8); $ url = http://www.google.com/ig/api?weather=shenzhen; Load XML content ...