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

preg_match_all m多行模式的问题,

WBOY
Release: 2016-06-23 13:47:38
Original
1279 people have browsed it

我打算用多行模式匹配文本

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


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

最终只匹配出最后一个  google

多行模式的意思不是每一行都匹配^$然后可以把每一行的匹配项拿出来吗?按理来说应该匹配所有行啊,
为什么只匹配了最后一行呢,求大神赐教~~


回复讨论(解决方案)

显然你遗漏了对 windows 的“回车”符的检查
这样才对
$pat = "#^[a-z0-9]+\r?$#m";

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

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