PHP regular expression solution

Source: Internet
Author: User
PHP regular expressions are used to retrieve 17 & nbsp; & lt ;? Xmlversion = & quot; 1.0 & quot; encoding = & quot; UTF-8 & quot ;? & Gt; & lt; response & gt; & lt; error & gt; 17 & lt;/error & gt; & lt; message & gt; synchronous sending of instant PHP regular expressions
Now use the regular expression to retrieve 17



17
Synchronously send instant SMS response results


I wrote it like this.
Preg_match ("/\ (. *) \ <\/Error \>/U ", $ string, $ state );

But output:
Array
(
[0] => 17
[1] => 17
)

What are the mistakes? I still use them.
Simplexml_load_string: an error is returned when parsing this XML file. This function is used to retrieve This node does not work. now only regular expressions can be used.
Table Help. thank you.

------ Solution --------------------
1. Regular expressions are correct.
You can use $ state [1] to get the error node value.

2. simplexml_load_string () if an error is reported. It is probably because of the file BOM header or inconsistent encoding.
------ Solution --------------------
The one you output is correct.
------ Solution --------------------
Your regular expression is correct. you can get $ state [1] and ignore the previous one.

When you use simplexml_load_string, the error code is "line breaks" in xml.
PHP code
    
    
     
      
17
     
     
      
Synchronously send instant SMS response results
     
    '; $ Obj = simplexml_load_string (str_replace (array ("\ r", "\ n", "\ t"), '', $ xml )); print_r ($ obj );
------ Solution --------------------
$ Xml = simplexml_load_string ($ s );
Echo $ xml-> error;

If an error occurs, it is because your encoding is inappropriate.

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.