首页 > 其他 > 详细

替换内容里面的图片

时间:2021-06-11 16:42:21      阅读:19      评论:0      收藏:0      [点我收藏+]

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-z\d\-]+[.]{1}[a-z\d]*/";
$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-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;
}

替换内容里面的图片

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!