How does PHP parse XML code? Is an SMS interface: the called code is as follows: $ res & nbsp ;=& nbsp; file_get_contents ("http: // XXXXXXX/webservice. asmx/mt? Sn = $ name & amp; Pwd = $ pwd & amp; mobile = PHP how to parse XML code?
Is an SMS interface: the called code is as follows:
$res = file_get_contents("http://XXXXXXX/webservice.asmx/mt?Sn=$name&Pwd=$pwd&mobile=$tel&content=$msg");
print_r($res);
Print_r ($ res) and get an XML code, as follows:
0
Have you seen 0 in this code? I marked it in red. If the returned value is 0, the message is sent successfully.
However, I cannot determine this:
If ($ res = "0 "){
Mysql_query ("update sms set etime = now (), wei = 'sent successfully' where sms_id = '$ sms_id '");
}
How can I determine to get 0 and update the sending status in the database?
------ Solution --------------------
Preg_match ('/ (. +) <\/Int>/S', $ res, $ r );
If ($ r [1] = "0 "){
Mysql_query ("update sms set etime = now (), wei = 'sent successfully' where sms_id = '$ sms_id '");
}
------ Solution --------------------
The returned xml is a string (and very short). you need to judge whether it is a string. Therefore, you do not need to parse xml first.
Of course, it is not an error to parse it. it only consumes more resources. load a dom class first and then parse
If you want to obtain an xml node (complex), consider the latter method.
# The regular expression of 3 is the same, but it is determined from the returned string.
In this case, you can execute and do not execute the Boolean value, so I think even the return can be saved.
It is enough to directly judge whether preg_match () is True.
Reference:
I don't understand. Should I use php to parse XML first?
Can someone help me with the version?