Home  >  Article  >  Backend Development  >  if(preg_match('/D/', $page) )什么意思解决思路

if(preg_match('/D/', $page) )什么意思解决思路

WBOY
WBOYOriginal
2016-06-13 10:47:451765browse

if(preg_match('/\D/', $page) )什么意思
if(preg_match('/\D/', $page) )

{$this->page=1;
}
else{
$this->page=$page;
}


------解决方案--------------------
分页?
如果页号($page)中存在非数字,则令页号为1

------解决方案--------------------
正则表达式,匹配$page是否包含数字
没有数字则 $this->page = 1;
------解决方案--------------------
if的条件 preg_match('/\D/', $page) 是正则匹配一次
在$page匹配非数字内容,\d是数字 \D是非数字
------解决方案--------------------
正则匹配,在$page匹配非数字内容,\d是数字 \D是非数字,此处还有\w表示大小写字母、数字、下划线,\W表示跟\w刚好相反,诸如此类!

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