Home  >  Article  >  Backend Development  >  求教小问题。

求教小问题。

WBOY
WBOYOriginal
2016-06-23 14:12:55810browse

<?php$subject = "abcdef";$pattern = '/^def/';preg_match($pattern, $subject, $matches);print_r($matches);?>

为啥什么也输出不了?


回复讨论(解决方案)

^表示开头,但字符串开头是abc而不是def,所以不能匹配

因为正则没有匹配,如果你想找最后的应该是 /def$/ ,这样就应该有输出了

<?php$subject = "abcdef";$pattern = '/^def/';preg_match($pattern, $subject, $matches);print_r($matches);?>

为啥什么也输出不了?

这是最简单问题,正则表达式的特殊字符含义还不是很清楚,建议抽时间学一下正则表达式吧。

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