Home > Backend Development > PHP Tutorial > preg_match_all m多行模式的有关问题

preg_match_all m多行模式的有关问题

WBOY
Release: 2016-06-13 12:08:00
Original
1820 people have browsed it

preg_match_all \m多行模式的问题,
我打算用多行模式匹配文本

<br /><?php<br />$str=file_get_contents('1.txt');<br />$pat="#^[a-z0-9]+$#m";<br />preg_match_all($pat,$str,$matches);<br />var_dump($matches);<br />?><br />
Copy after login


1.txt内容如下
hello
qunide
budui
nihao
goole

最终只匹配出最后一个  google

多行模式的意思不是每一行都匹配^$然后可以把每一行的匹配项拿出来吗?按理来说应该匹配所有行啊,
为什么只匹配了最后一行呢,求大神赐教~~
------解决思路----------------------
显然你遗漏了对 windows 的“回车”符的检查
这样才对
$pat = "#^[a-z0-9]+\r?$#m";

$pat = "#^[a-z0-9]+#m";

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