When using
Examples of how PHP Domxpath are used:
- < ? PHP
- Header ("content-type:text/html;
Charset=utf-8 ");
- $ URL = "http://www.google.com/ig/
Api?weather=shenzhen ";
- Loading XML content
- $ Dom = New DOMDocument ();
- $dom- > load ($url);
- $ XPath = New Domxpath ($dom);
- $ element = $xpath- > Query ("/xml_api_reply
/weather/current_conditions ")->item (0);
- $ condition = Get_google_xml_data
($element, "condition");
- $ Temp_c = Get_google_xml_data
($element, "Temp_c");
- echo ' weather: ', $condition, ' < br />';
- Echo ' temp: ', $temp _c, ' < br />';
- function Get_google_xml_data
($element, $tagname) {
- $ Tags = $element- >
getElementsByTagName ($tagname);
- Get all the $tagname
- if ($items->length > 1) {
- return $items;
- }
- $ Tag = $tags- > item (0);
- Gets the first label named $tagname
- if ($tag->hasattributes ()) {
- Get the Data property
- $ attribute = $tag- >
getattribute ("data");
- return $attribute;
- }else {
- return false;
- }
- }
- ?>
I hope that through the above code example, we can fully grasp the specific use of PHP Domxpath method.
http://www.bkjia.com/PHPjc/446187.html www.bkjia.com true http://www.bkjia.com/PHPjc/446187.html techarticle examples of how to use PHP Domxpath:? PHP header (content-type:text/html; Charset = Utf-8); $ url = http://www.google.com/ig/api?weather=shenzhen; Load XML content $ dom ...