php 根据白名单替换字符转中的链接 封装的函数
作者:互联网
function doreplace($str){
global $api,$empire,$class_r,$dbtbpre,$public_r;
// $list = $api->select("ecms_news");
// $urllist = $api->select("ecms_news_allow_weburl");
// // print_r($urllist);
$text=Repurl($str);
// print_r($text);
$exp1="[--copyurl--]";
$exp2="[/--copyurl--]";
$rr=explode($exp1,$text);
$j=1;
for($i=1;$i<count($rr);$i++)
{
$r1=explode($exp2,$rr[$i]);
$dourl=$r1[0];
// echo $dourl."<br>";
$one = $empire->fetch1("select * from {$dbtbpre}ecms_news_allow_weburl where url='{$dourl}'");
// print_r($one);
if(!$one){
$text = str_replace($exp1.$dourl.$exp2,'网址未加载',$text);
}else{
$text = str_replace($exp1.$dourl.$exp2,$dourl,$text);
}
}
// exit('123');
return $text;
}
//替换图片标签
function Repurl($text){
global $ecms_config;
$exp1="[--copyurl--]";
$exp2="[/--copyurl--]";
$pattern="/[.]{1}[a-z\d\-]+[.]{1}[a-z\d]*/";
// $pattern="/[.]{1}[a-z\d\-]+[.]{1}[a-z\d]*[\/]*[A-Za-z\d]*[\/]*[A-Za-z\d]*/";//匹配域名后整个链接
$text = preg_replace($pattern,$exp1."\${0}".$exp2,$text);
return $text;
}
标签:dourl,--,text,exp1,转中,ecms,exp2,白名单,php 来源: https://www.cnblogs.com/songadmin/p/14252529.html