开发者

Help with preg_match/regex

I don't know regex, so please help. For the following code:

$req_user = trim($_GET['user']);
if(!preg_match("^([0开发者_JAVA百科-9a-z])+$", $req_user)){
//do something ...
}

I get this error: NOTICE: No ending delimiter '^' found.


When giving a regex in php you need to put a matching character at the beginning and end of the string to delimit it. So, the complaint is that it sees a ^ at the start of the string, and assumes it is the delimiter, but there is no matching character at the end. As such, you really need a string like

"#^([0-9a-z])+$#"

when entering the regex in php.


$req_user = trim($_GET['user']); if(!preg_match("!^([0-9a-z])+$!", $req_user)){ //do something ... }

You have to add an Char on the start and end of the regexp to have it working. This char restricts the regexp-area. After the last ! you can add modifiers for case-ignore etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜