导航:首页 > 编程语言 > php正则匹配url参数

php正则匹配url参数

发布时间:2025-01-15 07:32:52

1. php 正则表达式如何添加URL参数 ,并把&替换成amp;

preg_replace('/(&|\\?)pagesize=[^&]+/', '', $_SERVER['REQUEST_URI']) str_replace 或replace 或preg_replace 用正则是比较笨的办法

2. PHP 正则表达式如何替换URL参数

用正则是比较笨的办法,但也给你提供一下了:

function getpage(){
//你可以把获取当前page的代码放在函数里
return 123;
}

$str = 'index.php?main_page=index&cPath=55&pagesize=48';
$ptn = '/&pagesize=(\d+)/';
$pagenum = getpage();
$rep = '&pagesize='.$pagenum;

echo $str; // 输出:index.php?main_page=index&cPath=55&pagesize=48

preg_replace($ptn,$rep,$str);

echo $str; // 输出:index.php?main_page=index&cPath=55&pagesize=123

另外多说一下,这种情况可以使用
http_build_query()
这个函数。

具体使用方法:
$u['main_page']=$_GET['main_page'];
$u['cPath']=$_GET['cPath'];
$u['pagesize']=getpage();

$url = 'index.php?'.http_build_query($u);
echo $url;

这个函数很好用,比你自己去匹配好。

3. php 正则表达式匹配到href的链接怎么写急!!!

$patten="/<ahref=['"]?([^'"]+).*?>/";

4. 用PHP正则将任何URL从文章中匹配出来,例如:http://.baidu.com/qct=17&pn=0&tn=ikask&rn=12&word

`I shall have my supper in another room,' I said. `Have you no place you call a parlour?'
`Parlour!' he echoed sneeringly, `parlour! Nay, we've noa parlours. If yah nnut loike wer company, there's maister's; un' if yah nnut loike maister, there's us.
`Then I shall go upstairs!' I answered; `show me a chamber.' I put my basin on a tray, and went myself to fetch some more milk. With great grumblings, the fellow rose, and preceded me in my ascent: we mounted to the garrets; he opening a door, now and then, to look into the apartments we passed.
`Here's a rahm,' he said, at last, flinging back a cranky board on hinges. `It's weel eneugh tuh ate a few porridge in. They's a pack o' corn i' t' corner, thear, meeterly clane; if yah're feared uh muckying yer grand silk cloes, spread yer hankerchir o' t' top on't.'
The `rahm' was a kind of lumber-hole smelling strong of malt and grain; various sacks of which articles were piled around, leaving a wide, bare space in the middle.
`Why, man!' I exclaimed, facing him angrily,coach outlet, `this is not a place to sleep in. I wish to see my bedroom.
`Bed-rume!' he repeated, in a tone of mockery. `Yah's see all t' bed-rumes thear is--yon's mine.'
He pointed into the second garret, only differing from the first in being more naked about the walls, and having a large, low, curtainless bed, with an indigo-coloured quilt at one end.
`What do I want with yours?' I retorted. `I suppose Mr Heathcliff does not lodge at the top of the house, does he?'
`Oh! it's Maister Hathecliff's yah're wenting!' cried he, as if making a new discovery. `Couldn't ye uh said soa, at onst? un then, Aw mud uh telled ye, baht all this wark,christian louboutin uk, ut that's just one yah cannut sea--he alIas keeps it locked, un nob'dy iver mells on't but hisseln.'
`You've a nice house, Joseph,' I could not refrain from observing, `and pleasant inmates; and I think the concentrated essence of all the madness in the world took up its abode in my brain the day I linked my fate with theirs! However, that is not to the present purpose--there are other rooms. For heaven's sake be quick, and let me settle somewhere!'
He made no reply to this adjuration; only plodding doggedly down the wooden steps, and halting before an apartment which, from that halt and the superior quality of its furniture, I conjectured to be the best one. There was a carpet: a good one, but the pattern was obliterated by st; a fireplace hung with cut paper, dropping to pieces; a handsome oak bedstead with ample crimson curtains of rather expensive material and modern make; but they had evidently experienced rough usage: the valances hung in festoons, wrenched from their rings, and the iron rod supporting them was bent in an arc on one side, causing the drapery to trail upon the floor. The chairs were also damaged, many of them severely; and deep indentations deformed the panels of the walls. I was endeavouring to gather resolution for entering and taking possession, when my fool of a guide announced, `This here is t' maister's.' My supper by this time was cold, my appetite gone,clarks shoes, and my patience exhausted. I insisted on being provided instantly with a place of refuge,clarks shoes uk, and means of repose.

5. 求PHP 的正则表达式 大全

匹配中文字符的正则表达式: [\u4e00-\u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^\x00-\xff] 评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1) 匹配空白行的正则表达式:\n\s*\r 评注:可以用来删除空白行 匹配HTML标记的正则表达式:<(\S*?)[^>]*>.*?</\1>|<.*? /> 评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为 匹配首尾空白字符的正则表达式:^\s*|\s*$ 评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式 匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* 评注:表单验证时很实用 匹配网址URL的正则表达式:[a-zA-z]+://[^\s]* 评注:网上流传的版本功能很有限,上面这个基本可以满足需求 匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$ 评注:表单验证时很实用 匹配国内电话号码:\d{3}-\d{8}|\d{4}-\d{7} 评注:匹配形式如 0511-4405222 或 021-87888822 匹配腾讯QQ号:[1-9][0-9]{4,} 评注:腾讯QQ号从10000开始 匹配中国邮政编码:[1-9]\d{5}(?!\d) 评注:中国邮政编码为6位数字 匹配身份证:\d{15}|\d{18} 评注:中国的身份证为15位或18位 匹配ip地址:\d+\.\d+\.\d+\.\d+ 评注:提取ip地址时有用 匹配特定数字: ^[1-9]\d*$ //匹配正整数 ^-[1-9]\d*$ //匹配负整数 ^-?[1-9]\d*$ //匹配整数 ^[1-9]\d*|0$ //匹配非负整数(正整数 + 0) ^-[1-9]\d*|0$ //匹配非正整数(负整数 + 0) ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //匹配正浮点数 ^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //匹配负浮点数 ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //匹配浮点数 ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //匹配非负浮点数(正浮点数 + 0) ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮点数(负浮点数 + 0) 评注:处理大量数据时有用,具体应用时注意修正 匹配特定字符串: ^[A-Za-z]+$ //匹配由26个英文字母组成的字符串 ^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串 ^[a-z]+$ //匹配由26个英文字母的小写组成的字符串 ^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串 ^\w+$ //匹配由数字、26个英文字母或者下划线组成的字符串 /http:\/\/(.*)\//i //匹配外部链接地址

满意请采纳

6. 怎么用php正则获得a标签内的文字啊

php中正则匹配只要使用这两个函数:

preg_match_all

preg_match

这里使用preg_match_all,代码如下:

$subject='<ahref="xxx.php">abc测试</a>';//假设这是需要匹配的字符串

$pattern='/<ahref="[^"]*"[^>]*>(.*)</a>/';//这是匹配的正则表达式

preg_match_all($pattern,$subject,$matches);//开始匹配,该函数会把匹配结果放入$matches数组中


echo"<pre>";
print_r($matches);
/**
结果是:

Array
(
[0]=>Array
(
[0]=>abc测试
)

[1]=>Array
(
[0]=>abc测试
)

)

*/

7. PHP 正则验证URL网址格式是否有效

PHP中的ereg()函数常用于验证URL地址格式是否正确。此函数返回布尔值,用于指示验证结果。下面是一个简单的函数示例,用于检查URL的有效性:

function CheckUrl($C_url){

if (!ereg("^http://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$", $C_url))

{

return false;

}

return true;

}

这个函数接收一个URL作为参数,通过正则表达式进行验证。如果URL不符合规则,函数返回false;反之,则返回true。正则表达式定义了URL的基本结构,确保其符合标准格式。

例如,正则表达式"^http://[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*$"可以解析出http或https开头的URL,其中[_a-zA-Z0-9-]+表示以字母、数字或破折号开头的字符串,(.[_a-zA-Z0-9-]+)*则表示可能存在的子域名部分。

利用ereg()函数进行URL验证是一种简单有效的方法。然而,需要注意的是,ereg()函数在PHP7中已被弃用,应考虑使用preg_match()等替代方法。preg_match()同样基于正则表达式,但在性能和功能上更为强大。

总之,通过正则表达式验证URL格式是确保数据完整性的重要步骤,特别是在处理用户输入时。正确的URL验证能够帮助防止潜在的安全威胁,并确保应用程序的正常运行。

8. php如何正则匹配出带问号的域名来php如何正则匹配出带问号的域名来源

PHP-如何在PHP中使用正则表达式匹配URL中的域名

马鞭php

//从URL获取主机名

preg_match(/^(http://)?(【^/])/i,,$matches);

$host=$matches[2];

//从主机名中获取最后两段

preg_match(/[^./].[^./]$/,$host,$matches);

回声;

马鞭month=$month中的$php_self是链接地址,这里给出的是一个变量来代替冗长的字符串,比如说www.phpfans.net,问号后面的year、month传的参数,并分别给他们赋值为$y-lnk、$month。添加该链接出错是语法错误!将双引号去掉即可。

mysql中?号是什么?

问号表示稍后将被replace的参数。使用参数化查询比将参数直接embedded查询更安全。

SQLServer调用这个参数化查询,而Oracle调用它绑定variables。

用法因您执行查询的语言而异。

这里是一个如何使用PHP的例子。

假设$mysqli是一个数据库连接,而people是一个有4列的表。

阅读全文

与php正则匹配url参数相关的资料

热点内容
怎么查询哪个app是哪个公司的 浏览:731
我的世界服务器地址怎么变成ip地址 浏览:31
不用时怎么加密电脑 浏览:54
不玩手机APP怎么开启警报 浏览:560
打开微信收付款加密 浏览:400
小度app怎么关闭看护助手 浏览:739
服务器方舟boss属性怎么调 浏览:345
acos系统终端命令 浏览:915
宁德云服务器最新行情 浏览:475
压缩性骨折五十天 浏览:656
如何在服务器里把方块替换 浏览:909
变频空调摘板用什么替代压缩机 浏览:46
怎么在苹果手机上玩安卓和平精英 浏览:237
python异步调用框架 浏览:963
安卓手机如何拍live图 浏览:823
供应链管理系统源码 浏览:944
方舟编译器会适配哪些型号 浏览:470
主流云服务器哪个牌子好 浏览:267
导航怎么看服务器在那 浏览:932
广石化单片机 浏览:281