PHP中preg_match_all函数正则匹配详解
来源:互联网 发布:java 发送http请求 编辑:程序博客网 时间:2024/05/18 01:20
preg_match_all — 执行一个全局正则表达式匹配
int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0 ]]] )
例
代码如下复制代码preg_match_all("|<[^>]+>(.*)]+>|U",
"example:
$out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "n";
echo $out[1][0] . ", " . $out[1][1] . "n";
?>
如何获取伪静态url中的参数变量,已经对应的值。
比如说。你现在url的是这样的。/js/d1b3cid419299191rs好脚本
你的.htaccess文件会这样写rewirte规则 RewriteRule ^js/(.*)$ /index.php?m=Sell&a=index&g=$1 [QSA,PT,L]
这样你就可以把g接收过来。
代码如下复制代码$get = 'd1b3cid419299191rs好脚本';
$rs_pos = strpos($get,'rs');
if($rs_pos !== false)
{
$rs = substr($get,$rs_pos);
$rs = str_replace('rs','',$rs);
$rs = strpos($rs,'/')!==false ? substr($rs,0,strpos($rs,'/')) : $rs;
$get = substr($get,0,$rs_pos);
}
echo 'keywords='.$rs;
echo '
';
preg_match_all('/([a-z]*)([0-9]+)/',$get,$m);
if($m)
{
$k = $v = '';
$count = count($m[1]);
for($i = 0; $i <= $count; $i++)
{
${$m[1][$i]} = $m[2][$i];
if(isset(${$m[1][$i]}))
{
echo $m[1][$i].'='.${$m[1][$i]};
echo '
';
}
}
}
结果:keywords=好脚本,d=1,b=3,cid=419299191
匹配文章中的图片
代码如下复制代码
$con = file_get_contents("http://www.php100.com/");
$pattern="/<[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg|.png]))['|"].*?[/]?>/";
preg_match_all($pattern,$con,$match);
print_r($match);
?>
输出代码
Array
(
[0] => Array
(
[0] =>
[1] =>
[2] =>
)
[1] => Array
(
[0] => http://www.php100.com/uploadfile/2013/0905/20130905074915895.png
[1] => http://www.php100.com/uploadfile/2013/0905/20130905074915639.jpg
[2] => http://www.php100.com/uploadfile/2013/0905/20130905074915742.jpg
)
)
- PHP中preg_match_all函数正则匹配详解
- PHP 正则表达式匹配 preg_match 与 preg_match_all 函数
- PHP 正则preg_match 与 preg_match_all 函数以及匹配中文
- PHP 正则表达式匹配 preg_match 与 preg_match_all 函数
- PHP 正则表达式匹配 preg_match 与 preg_match_all 函数
- 正则匹配 preg_match与preg_match_all 函数
- PHP preg_match_all详解
- php preg_match_all函数笔记
- PHP函数preg_match_all正则表达式的简单应用
- PHP函数preg_match_all正则表达式的简单应用
- preg_match_all函数详解
- php preg_match()与preg_match_all()函数
- preg_match_all()匹配
- PHP 用正则表达式preg_match_all抓取天气预报
- PHP中的正则匹配函数
- php preg_match_all preg_match 的用法详解
- php中使用正则表达式匹配的函数
- javascript 正则匹配 提取全部 preg_match_all matchAll方法
- 发邮件的协议: smtp 协议:
- 【第六周 项目5 - 后缀表达式】
- 使用Facebook开源项目Stetho 在Chrome上调试Android网络、数据库
- 11.2.0.4 Restore OCR
- ansible模块示例
- PHP中preg_match_all函数正则匹配详解
- 深拷贝和浅拷贝
- 类与类之间的几种关系
- 网络编程的最佳实践
- 收取邮件的协议 : pop3 exchange imap
- 第2章 信息的表示和处理
- 关于阻塞,非阻塞,同步,异步
- string转换成char*
- 【jQuery】jQuery双击事件与单击事件的冲突解决