PHP read XML, there is a problem, thank you.

Source: Internet
Author: User
Tags sha1 xpath
The XML file is:
 
  
  
   
    
   http://114.80.235.12
  
   
  
   
    
   http://114.80.236.202
  
   
  
   
 
  
 
  

My PHP code is written like this, but I can't read it. Thank you.
2. Read Xml$xml_array=simplexml_load_file ("Wc.xml"); Reads the data from the XML into the array object in the foreach ($xml _array as $temp) {echo '
";p Rint_r ($temp->f); echo"
";}


My goal is to read the middle of that two HTTP address. Thank you, sir.


Reply to discussion (solution)

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

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

Thank you, can I trouble you to say clearly, I Baidu a, no things

Print_r ($xml _array->a->f);

$s =<<< XML
 
  
  
   
    
   http://114.80.235.12
  
   
  
   
    
   http://114.80.236.202
  
   
  
    XML; $xml = simplexml_load_string ($s);//normal traversal, need to know exactly where the target node is at the level of foreach ($xml as $temp
 
   ) {  foreach ($temp->f as $v) echo "$v
 
  
   
  XPath ('//f ') as $v) echo" $v
  
   
";
All can be obtained
http://114.80.235.12
http://114.80.236.202

[code=php] $s =<<< XML


Thank you brother for helping. Wish you happy every day.
I would like to strengthen my study, what is this knowledge? What knowledge should I search? Thank you, sir.

If you Print_r ($xml _array); You can see

SimpleXMLElement Object (    [@attributes] = = Array        (            [TIME] = 180530            [vi] = 1            [ch] = 29            [NLS] = 0            [title] + [Control] [            code] = qt4j-61ws-q            [enable] + 1            [logo] + 0            [WT] = 0            [band] =& Gt 0        )    [a] = = SimpleXMLElement Object        (            [f] = = Array                (                    [0] =/http 114.80.235.12                    [1] = http://114.80.236.202                )        )    [b] = simplexmlelement Object        (        ))
Such a structure, it is easy to write code according to this. Don't repeat it.

XPath is a language that looks for information in an XML document. XPath is used to navigate through elements and attributes in an XML document.
You can search for XPath to find tutorials such as http://www.w3school.com.cn/xpath/

 
  
 
  
   
  http://114.80.235.12
 
  
 http://114.80.236.202XML; $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;? >

Uh, a second address? #1的才正确
f[2]/text ()
The XPath counter is starting from 1.

  • Related Article

    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.