PHP 正则匹配 a 链接

简介: $html='<div class="prop_1 clearfixs">';$html.="\n";$html.='<span class="prop_s"> <a class="a1">21条</a> <a href="http://125life.com/index.php?r=lfb%2Fdh%2Fsearch&
$html='<div class="prop_1 clearfixs">';
$html.="\n";
$html.='<span class="prop_s">
  <a class="a1">21条</a> <a href="http://125life.com/index.php?r=lfb%2Fdh%2Fsearch&catid=0&page=0" class="a1">上一页</a> <span>1</span> <a href="http://125life.com/index.php?r=lfb%2Fdh%2Fsearch&catid=0&page=2">2</a> <a href="http://125life.com/index.php?r=lfb%2Fdh%2Fsearch&catid=0&page=2" class="a1">下一页</a></span>
</div>';
echo preg_replace('/(<a[\S\s]*?href=")[^"]*?page=(\d)("[\S\s]*?>)/','$1javascript:LFB.SearchSetPage($2);$3',$html);

结果如下

<div class="prop_1 clearfixs">
<span class="prop_s">
  <a class="a1">21条</a> <a href="javascript:LFB.SearchSetPage(0);" class="a1">上一页</a> <span>1</span> <a href="javascript:LFB.SearchSetPage(2);">2</a> <a href="javascript:LFB.SearchSetPage(2);" class="a1">下一页</a></span>
</div>

目录
相关文章
|
PHP
php链接sqlserver的四种方法
php链接sqlserver四种方法分别是mssql、pdo-mssql、sqlsrv-pdo、sqlsrv 对应php.ini的以下4个,去掉前面的分号注释后可能需要相关的驱动文件。
688 0
php链接sqlserver的四种方法
|
2天前
|
关系型数据库 MySQL PHP
|
2天前
|
PHP
php 正则匹配 常用的 规则(一) 匹配form表单
php 正则匹配 常用的 规则(一) 匹配form表单
9 0
|
2天前
|
PHP
php 正则匹配 规则(二)匹配form表单 示例
php 正则匹配 规则(二)匹配form表单 示例
12 0
|
2天前
|
搜索推荐 小程序 Linux
分享88个搜索链接PHP源码,总有一款适合你
分享88个搜索链接PHP源码,总有一款适合你
106 0
|
10月前
|
Java PHP C++
PHP快速入门09-正则相关,附一定要学会的20个高频使用案例
PHP快速入门09-正则相关,附一定要学会的20个高频使用案例
|
10月前
|
PHP
PHP获取根目录下子文件夹作为链接的解决方案
PHP获取根目录下子文件夹作为链接的解决方案
36 0
|
10月前
|
PHP
php函数file_get_contents无法获取到https链接内容问题使用curl的解决方案
php函数file_get_contents无法获取到https链接内容问题使用curl的解决方案
113 0
|
10月前
|
JSON PHP 数据格式
PHP中json传递请求字符串网址函数http_build_query()与parse_str(),将POST参数组转换拼接成GET请求链接
PHP中json传递请求字符串网址函数http_build_query()与parse_str(),将POST参数组转换拼接成GET请求链接
101 0
|
12月前
|
PHP
PHP正则匹配中文
PHP正则匹配中文