替换内容里面的图片

function doreplace($str){
global $api,$empire,$class_r,$dbtbpre,$public_r;

$text=Repurl($str);
$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];
$dourl = trim($dourl,'.');
// echo $dourl."<br>";

if(!strstr($dourl, '.edu')){
if(!strstr($dourl, '.gov')){
// if(!strstr($dourl, 'js')||!strstr($dourl, 'css')){
$one = $empire->fetch1("select * from {$dbtbpre}ecms_news_allow_weburl where url like '%{$dourl}%'");
// print_r($one);
if(empty($one)){
// echo "1";
// $dourl = $one[url];
$text = str_replace($exp1.$dourl.$exp2,'网址未加载',$text);
}else{
// echo "2";
$text = str_replace($exp1.$dourl.$exp2,$dourl,$text);
// echo $text;
}
// }else{
// $text = str_replace($exp1.'.'.$dourl.$exp2,'.'.$dourl,$text);
// }
}else{
$text = str_replace($exp1.$dourl.$exp2,$dourl,$text);
}
}else{
$text = str_replace($exp1.$dourl.$exp2,$dourl,$text);
// $text = str_replace($exp1.'.'.$dourl.$exp2,'.'.$dourl,$text);
}
// echo $dourl."<br>";
}
// exit('123');
return $text;
}

//替换图片标签
function Repurl($text){
global $ecms_config;
$exp1="[--copyurl--]";
$exp2="[/--copyurl--]";
$pattern = "/[a-z0-9][a-z0-9-]*?.(?:com|cn|net|org|gov|cc)(?:.(?:cn))?/";
// $pattern = "/[.]{1}[a-zd-]+[.]{1}[a-zd]*/";
$str = '';
// $isMatched = preg_match('/[a-z0-9][a-z0-9-]*?.(?:com|cn|net|org|gov|cc)(?:.(?:cn))?/', $str, $matches);
// var_dump($isMatched, $matches);
// '~^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(?([^#]*))?(#(.*))?~i';
// $pattern="/[a-z0-9][a-z0-9-]*?.(?:com|cn|net|org|gov|info|la|cc|co|jp)(?:.(?:cn|jp))?/";
// "(.)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(.(net|com|cn|org|cc|tv))+.?"
// $pattern="/[.]{1}[a-zd-]+[.]{1}[a-zd]*/";
// $pattern="/[.]{1}[a-zd-]+[.]{1}[a-zd]*[/]*[A-Za-zd]*[/]*[A-Za-zd]*/";//匹配域名后整个链接
$text = preg_replace($pattern,$exp1."${0}".$exp2,$text);
return $text;
}

原文地址:https://www.cnblogs.com/songadmin/p/14875018.html