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

preg_match_all m多行模式的问题,

WBOY
WBOYOriginal
2016-06-23 13:47:381255browse

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

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


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

最终只匹配出最后一个  google

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


回复讨论(解决方案)

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

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

Statement:
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