Home > Backend Development > PHP Tutorial > 想不明白的PHP正则有关问题

想不明白的PHP正则有关问题

WBOY
Release: 2016-06-13 10:25:14
Original
847 people have browsed it

想不明白的PHP正则问题
【代码】
$str= HTML...




HTML...
EOD;

$reg1='/]*>(.(?!$reg2='/|[^>]+>)/s';
$reg3='/]*>(.(?!|[^>]+>)/s';

preg_match ($reg1,$str,$out1);
preg_match ($reg2,$str,$out2);
preg_match ($reg3,$str,$out3);

echo "$str\n\n\n
";<br>print_r($out1);<br>print_r($out2);<br>print_r($out3);<br><br><br><br>【输出】<br>HTML...<br><object width="425" height="350"><br><param name="movie" value="http://www.atungm.com/v/AyPzM5WK8ys">
<br><embed src="http://www.atungm.com/v/AyPzM5WK8ys" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed><br></object><br>HTML...<br><br><br><pre class="brush:php;toolbar:false"><br>Array<br>(<br>     [0] => <object width="425" height="350"><br><param name="movie" value="http://www.atungm.com/v/AyPzM5WK8ys">
<br>     [1] =>  <br>)<br>Array<br>(<br>     [0] => <embed src="http://www.atungm.com/v/AyPzM5WK8ys" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed><br>     [1] =>  src="http://www.atungm.com/v/AyPzM5WK8ys" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350" ></object>
Copy after login

)
Array
(
)



【问题】
正则表达式1、正则表达式2分别准确完整地匹配到目标字符串的前后两部分;
正则表达式3是正则表达式1、正则表达式2的整合,却出现了问题,匹配不到内容;
尝试了好久也找不出,正则表达式1、正则表达式2之间有什么冲突的地方?

我只有14分资源分,全部给了也就这么多了。
不知道哪位高手能指导一下?

------解决方案--------------------
$reg3='/]*>(.(?!|[^>]+>)/s';

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template