Home  >  Article  >  Backend Development  >  请教分页中的 (^|&) 这句正则是什么意思,看不明白

请教分页中的 (^|&) 这句正则是什么意思,看不明白

WBOY
WBOYOriginal
2016-06-13 12:11:23938browse

请问分页中的 (^|&) 这句正则是什么意思,看不明白
网上常见的通用分页函数:
其中这句正则是什么意思?
$url_query=ereg_replace("(^|&)page=$page","",$url_query);/

(^|&)
这句正则是意思:

^代表起始位置;或者在[^..]代表非;
|是或的意思;
------
(^|&)是^或& 还是什么? 另外网址中不可能出现^这个符号啊;为什么要替换^
即使要替换^也应该加个转义符吧;
------解决思路----------------------
^ 表示字符串开始
& 表示字符 &
^
------解决思路----------------------
& 表示从字符串开始或字符 & 开始

你的规则串期望能匹配到:
page=1
id=2&page=1
------解决思路----------------------
空或者&開頭,後跟page的規則

http://www.example.com/?page=1
http://www.example.com/?action=list&page=1
------解决思路----------------------
少用正则表达式
------解决思路----------------------
空字条或 & 开头的匹配

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