求教小问题。

WBOY
Release: 2016-06-23 14:12:55
Original
809 people have browsed it

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

为啥什么也输出不了?


回复讨论(解决方案)

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

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

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

为啥什么也输出不了?

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

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