Php reads xml. if you have any questions, thank you.

Source: Internet
Author: User
Php reads xml. if you have any questions, thank you. The xml file is:
 
  
   
Http: // 114.80.235.12
  
  
   
Http: // 114.80.236.202
  
  
 
 

My php code is written in this way, but cannot be read. Thank you.
// 2. read xml $ xml_array = simplexml_load_file ("wc. xml "); // read the data in XML to the array object foreach ($ xml_array AS $ temp) {echo"
";print_r($temp->f);echo "
";}


My goal is to read the two http addresses in the middle. Thank you.


Reply to discussion (solution)

Xpath = '// f [2]/text ()'

Xpath = '// f [2]/text ()'

Thank you. could you please make it clear that I am Baidu and have nothing to do?

Print_r ($ xml_array-> a-> f );

$ S = <XML
 
  
   
Http: // 114.80.235.12
  
  
   
Http: // 114.80.236.202
  
  
 XML; $ xml = simplexml_load_string ($ s); // for normal traversal, you need to know exactly the level of the target node foreach ($ xml AS $ temp) {foreach ($ temp-> f as $ v) echo "$ v
 
  
Xpath ('// f') as $ v) echo "$ v
  
";
Can be obtained
Http: // 114.80.235.12
Http: // 114.80.236.202

[Code = php] $ s = <XML


Thank you for your support. Happy every day.
I want to learn more. what kind of knowledge does this mean? What knowledge should I search? Thank you.

If print_r ($ xml_array );

SimpleXMLElement Object ([@ attributes] => Array ([time] => 180530 [vi] => 1 [ch] => 29 [nls] => 0 [title] => monitoring real shot [code] => qT4j-61ws-Q [enable] => 1 [logo] => 0 [wt] => 0 [band] => 0) [a] => SimpleXMLElement Object ([f] => Array ([0] => http: // 114.80.235.12 [1] => http: // 114.80.236.202 )) [B] => SimpleXMLElement Object ())
This structure makes it easy to write code accordingly. No more details

XPath is a language used to search for information in XML documents. XPath is used to navigate through elements and attributes in XML documents.
You can search for xpath to find a tutorial, such as a http://www.w3school.com.cn/xpath/.

 
 
  
Http: // 114.80.235.12
 
 
  
Http: // 114.80.236.202
 XML; $ doc = new DOMDocument (); $ doc-> loadXML ($ s); $ xpath = new DOMXPath ($ doc ); $ query = '// f [1]/text ()'; $ entries = $ xpath-> evaluate ($ query, $ doc ); // foreach ($ entries as $ entry) var_dump ($ entry); foreach ($ entries as $ entry) echo $ entry-> data; $ xml = simplexml_load_string ($ s ); foreach ($ xml-> xpath ('// f [1]/text ()') as $ v) echo $ v;?>

Er, is it the second address? #1 is correct
// F [2]/text ()
The xpath counter starts from 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.