How does this XML use SimpleXML parsing, Vardump always False

Source: Internet
Author: User
Tags printable characters
Moderator, again to help ... This is the Web page returned by the XML data, I do not know why can not read with SimpleXML, Var_dump display false

Echo ' ######################### '. '

'; Var_dump ($xml); Echo ' ######################### '; Echo '
'.'
'.'
'. $xml->xsm->nickname;

If this is the case with the above direct printing:

Echo ' ######################### '. '

'; Var_dump (simplexml_load_string ($xml); Echo ' ######################### '; Echo '
'.'
'.'
'. $xml->xsm->nickname;

Print with this code to display bool (false)
seek to solve


Reply to discussion (solution)

$xml = Preg_replace ('/!| --/', ', $xml); Var_dump (Simplexml_load_string ($xml));

$xml = Preg_replace ('/!| --/', ', $xml); Var_dump (Simplexml_load_string ($xml));


$xml = "
 
   ; $xml = Preg_replace ('/!--\?| --/', ', $xml); Var_dump ($xml);

So I tried, a single row can be matched, but it's not valid in this code. See the returned value or comment in the page element viewer

Why are you trying to be smart?

$xml = Preg_replace ('/!| --/', ', $xml); Var_dump (Simplexml_load_string ($xml));


I did not understand that is the XML comment, now understand, so think of another method, but still failed, can you tell me the reason?
$xml = '
 
  
  . $xml; Var_dump (simplexml_load_string ($xml));
 

I used a string operator to add a line of XML to the file tag, but still show failure when using simplexml_load_string

Why do you want to be a smart guy or something?

Why are you trying to be smart?


The code you gave me is not loaded ...

That's because you didn't give me your data.

Why do you want to be a smart guy or something?



This is directly copied to my post code to run the results ...

Still have to get rid of simplexml loaded statements to dump them out.

It's no use to you!
How do you know that there are no non-printable characters?

That's because you didn't give me your data.


 
  
 
  
   
  WEDC 2 
   
  
   
  
   
  
   
  
   
  
   
  
   
  
   
  
   
    
   11601
  
   
  
   
    
   1062014
  
   
  
   
  
   
  
   
  
   
    
   v=2014080600 11620001
  
   
  
   
  
   
  
   
  
   
    
   1407488228735
  
   
  
   
    
   10116226011162288228735
  
   
  
   
    
   c6959b4eacf7b2f
  
   
 
  

This is the $xml value I wrote with Fwrite.

There is no comment out the file mark, but do not know what to ask not to load

It's no use to you!
How do you know that there are no non-printable characters?


Viewing under IE will show
The end tag ' xsm ' does not match the start tag ' comshort '.

SimpleXMLElement Object (    [@attributes] = = Array        (            [code] = 0000            [MSG] = + Verify success ABC            [trans _time] = 20140808162708        )    [UserId] [    nickname] = WeDC    [usertype]    = 2 [Comid] = >    [Saledptid] = 11601    [refId] = 1062014    [Comname] = simplexmlelement Object        ( c14/>)    [Domainurl] = v=2014080600    [ComType] = [    comshort] = simplexmlelement Object        (        )    [Parentcomid] = 11620001    [Expirationtime] = 1407488228735    [Plantext] = = 10116226011162288228735    [SignatureValue] = c6959b4eacf7b2f)
Isn't that okay?

You display a string length of 984 bytes, and you post only 509 bytes.
There's more than 400 bytes.

It's no use to you!
How do you know that there are no non-printable characters?


Moderator, I know, the reason is that there is Chinese so can not be loaded, how can this be solved? Because the data is not my own, so I can't change it.

SimpleXMLElement Object (    [@attributes] = = Array        (            [code] = 0000            [MSG] = + Verify success ABC            [trans _time] = 20140808162708        )    [UserId] [    nickname] = WeDC    [usertype]    = 2 [Comid] = >    [Saledptid] = 11601    [refId] = 1062014    [Comname] = simplexmlelement Object        ( c14/>)    [Domainurl] = v=2014080600    [ComType] = [    comshort] = simplexmlelement Object        (        )    [Parentcomid] = 11620001    [Expirationtime] = 1407488228735    [Plantext] = = 10116226011162288228735    [SignatureValue] = c6959b4eacf7b2f)
Isn't that okay?

You display a string length of 984 bytes, and you post only 509 bytes.
There's more than 400 bytes.


and 400 bytes is a long string of strings too long, I'm going to delete half.
Thank you, I found the reason, because PHP is encoded with UTF8, and the obtained XML data GBK, the file GBK changed to UTF8 to solve the

SimpleXMLElement Object (    [@attributes] = = Array        (            [code] = 0000            [MSG] = + Verify success ABC            [trans _time] = 20140808162708        )    [UserId] [    nickname] = WeDC    [usertype]    = 2 [Comid] = >    [Saledptid] = 11601    [refId] = 1062014    [Comname] = simplexmlelement Object        ( c14/>)    [Domainurl] = v=2014080600    [ComType] = [    comshort] = simplexmlelement Object        (        )    [Parentcomid] = 11620001    [Expirationtime] = 1407488228735    [Plantext] = = 10116226011162288228735    [SignatureValue] = c6959b4eacf7b2f)
Isn't that okay?

You display a string length of 984 bytes, and you post only 509 bytes.
There's more than 400 bytes.
Success of ~~~~~~[]
  • 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.