dede数据库内容替换 正则替换

http://zhidao.baidu.com/question/221359570.html

dede数据库内容替换 正则替换_第1张图片

方法二--->根目录新建--->regexp.php  作用--->去除超链接

<?php
/*
	author:miaoyaoyao
	说明:如是影响的条数为-1,则证明替换失败。
*/
require_once("./include/common.inc.php");//使用的时候更改一下引用文件名
$sql="select aid,body from #@__addonarticle where body like '%www.abc.com%'";
$row=0;
$dsql->execute('me',$sql);

while($rs=$dsql->getArray('me')){

$pattern='/<a.*href=".*www\.abc\.com\/.*.*>(.*)<\/a>/U';
$str=$rs['body'];
$replacement='${1}';
$str2=preg_replace($pattern,$replacement,$str);

$aid=$rs['aid'];
//$sqlbak="update_addonarticel set body='$str' where aid=$aid";
//file_put_contents("./logbak.txt",$sqlbak.';',FILE_APPEND);//主要是为了防止替换错误恢复使用
$replacesql="update #@__addonarticle set body=replace(body,'$str','$str2') where aid=$aid";//使用的时候更改一下表名
//echo '<br />'.$replacesql;
if(!$dsql->executenonequery($replacesql)){
	echo "error-aid--->".$rs['aid'].'<br/>';
};
//file_put_contents("./log.txt",$replacesql,FILE_APPEND);
$row++;

}
echo '影响的条数'.$row;
?>

你可能感兴趣的:(dede数据库内容替换正则替换,正则批量替换)