Home Backend Development PHP Tutorial PHP正则解决方案

PHP正则解决方案

Jun 13, 2016 pm 01:37 PM
error gt lt quot simplexml

PHP正则
现在要用正则取出里面 17
 


17
同步发送即时短信返回结果


我是这样写的
preg_match("/\(.*)\/U",$string,$state);

但是输出:
Array
(
  [0] => 17
  [1] => 17
)

哪些错了啊,还有我用
simplexml_load_string解析这个XML报错,本想用这个函数取这个节点,但是不行,现在只能用正则了
表帮帮忙,谢谢。

------解决方案--------------------
1.正则没错。
你可以用$state[1]获取到error节点的值。

2.simplexml_load_string()如果报错。很可能是文件BOM头的原因或者编码不一致原因。
------解决方案--------------------
你那个输出时正确的
------解决方案--------------------
你的正则没有错,你取$state[1]就行了 前面那个不用理会

你用simplexml_load_string报错 八成是xml里面的换行符 回车符导致的 把它们都替换掉

PHP code

$xml='<?xml version="1.0" encoding="UTF-8"?>
<response>
<error>17</error>
<message>同步发送即时短信返回结果</message>
</response>';

$obj=simplexml_load_string(str_replace(array("\r","\n","\t"),'',$xml));
print_r($obj);
<br><font color="#e78608">------解决方案--------------------</font><br>$xml = simplexml_load_string($s);<br>echo $xml-&gt;error;<br><br>如果出错,是因为你的编码不合适<br> <div class="clear">
                 
              
              
        
            </div>
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

Solution to PHP Fatal error: Call to undefined method PDO::prepare() in Solution to PHP Fatal error: Call to undefined method PDO::prepare() in Jun 22, 2023 pm 06:40 PM

Solution to PHP Fatal error: Call to undefined method PDO::prepare() in

Solve the problem of 'error: incomplete type is not allowed' in C++ code Solve the problem of 'error: incomplete type is not allowed' in C++ code Aug 26, 2023 pm 08:54 PM

Solve the problem of 'error: incomplete type is not allowed' in C++ code

What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application? What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application? Jun 24, 2023 pm 05:33 PM

What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application?

0271: What should I do if the computer cannot be turned on due to real time clock error? 0271: What should I do if the computer cannot be turned on due to real time clock error? Mar 13, 2023 am 11:30 AM

0271: What should I do if the computer cannot be turned on due to real time clock error?

Solve the 'error: expected initializer before 'datatype'' problem in C++ code Solve the 'error: expected initializer before 'datatype'' problem in C++ code Aug 25, 2023 pm 01:24 PM

Solve the 'error: expected initializer before 'datatype'' problem in C++ code

How to solve PHP Warning: fopen(): failed to open stream: No such file or directory How to solve PHP Warning: fopen(): failed to open stream: No such file or directory Aug 19, 2023 am 10:44 AM

How to solve PHP Warning: fopen(): failed to open stream: No such file or directory

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Fix: Snipping tool not working in Windows 11

See all articles