Home > Backend Development > PHP Tutorial > 求帮解一php正则判断!

求帮解一php正则判断!

WBOY
Release: 2016-06-06 20:13:56
Original
1013 people have browsed it

我想判断 $_SERVER['REQUEST_URI']
比如它是 /price/xilie-123-abc.html
我用以下方法就是批配不上,帮看看是什么原因,谢谢!

以下是我的代码:

<code>        $abc=$_SERVER['REQUEST_URI'];

        if(preg_match("/\/price\/xilie-\d-[abc|nba|cba]\.html/",$abc)){ 
            echo "是";  
        }else{  
            echo "不是";  
        }  </code>
Copy after login
Copy after login

回复内容:

我想判断 $_SERVER['REQUEST_URI']
比如它是 /price/xilie-123-abc.html
我用以下方法就是批配不上,帮看看是什么原因,谢谢!

以下是我的代码:

<code>        $abc=$_SERVER['REQUEST_URI'];

        if(preg_match("/\/price\/xilie-\d-[abc|nba|cba]\.html/",$abc)){ 
            echo "是";  
        }else{  
            echo "不是";  
        }  </code>
Copy after login
Copy after login

\d只能配对一个数字,不能配对多个数字,需要配对多个数字,需要使用\d+

<code>/\/price\/xilie\-\d{3}-(abc|nba|cba)\.html/</code>
Copy after login

我觉得你可以先看看这个...

<code>http://www.cnblogs.com/baochuan/archive/2012/03/12/2391135.html
http://www.cnblogs.com/afarmer/archive/2011/08/29/2158860.html</code>
Copy after login
Related labels:
php
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