Home > Backend Development > PHP Tutorial > php正则匹配为什么不成功?求助

php正则匹配为什么不成功?求助

WBOY
Release: 2016-06-23 14:28:33
Original
948 people have browsed it

正则 php

if(preg_match("^[a-zA-Z][a-zA-Z0-9_\-]{5,19}$", "abc-mmm") )
    echo "true";
else echo "false";

?>

想验证账号的正则表达式,字母开头,允许数字,字母,下划线,减号,6-20为,这个表达式为啥不成功啊?

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in test.php on line 3
false

试过"^[a-zA-Z][a-zA-Z0-9_-]{5,19}$",取掉“\”也不对,求大神知道(utf8格式的)

回复讨论(解决方案)


preg_match("/^[a-zA-Z][a-zA-Z0-9_-]{5,19}$/", "ml-virgil") )


刚试过前后加" /"就行,这是为啥?我是php新手不懂,求大神指导

那个叫定界符。不加定界符的话,PHP就认定为^[a-zA-Z][a-zA-Z0-9_-]{5,19}$是字符串,而不是变量。

我们经常管"\"叫"跳脱字符",用于转义一些特殊符号。

那个叫定界符。不加定界符的话,PHP就认定为^[a-zA-Z][a-zA-Z0-9_-]{5,19}$是字符串,而不是变量。 是这样啊,那请教大神个问题,我把英文和中文用“\n”连起来存入mysql,php编码和mysql都是utf-8为啥在phpadmin中查到的是"0”,数据类型是text的?困扰我好久啊。。。

搞定了,sql语句问题,真是大意。结贴啦,谢谢

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