您現在的位置╃▩: 首頁 > 新聞 > 建站常識

destoon改造MIP文章內容img正則替換mip-img方法

來源╃▩:網路公司釋出時間╃▩:2021-04-26熱度╃▩:28977

 

首先第一步↟↟✘│·,找到你修改的模組↟↟✘│·,我以資訊模組為例╃▩:

路徑為╃▩:/module/article/show.inc.php

然後開啟↟↟✘│·,大概在18行左右 插入一下程式碼↟↟✘│·,進行正則替換


function mip_replace($content = ''){
$pattern1 = "#<img.*?src=['\"](.*?)['\"].*?>#ims";
$imgcontent=array();
preg_match_all($pattern1,$content,$img);
$imgcontent = $img[0];
$imgurl = $img[1];
foreach($imgcontent as $imgk=>$imgv)
{
$temp =  str_replace('<img','mip-img',$imgv);
$temp = str_replace('/>','></mip-img',$temp);
$url = $imgurl[$imgk];
$url = mip_format_img_url($url);
$temp = preg_replace("/src=['\"].*?['\"]/si","src=http://www.kwsolidarity.com/skin/mall/image/nopic.gif>
$mipimg[$imgk] = $temp;
}
$content = preg_replace($imgcontent,$mipimg,$content);
$content =preg_replace("/<a /si","<a target=\"_blank\" ",$content);
$content =preg_replace("/style=\".*?\"/si","",$content);
return mip_utf8($content);
}
function mip_format_img_url( $url = ''){
if(stripos($url, 'http') === 0 || stripos($url, 'ftp') === 0 ){
return $url;
}
if(stripos($url, '/') === 0){
$url = 'http://'.$_SERVER['HTTP_HOST'].$url;
}else{
$url = 'http://'.$_SERVER['HTTP_HOST'].'/'.$url;
}
return $url;
}
function mip_utf8($string = '') {
$fileType = mb_detect_encoding($string , array('UTF-8','GBK','LATIN1','BIG5'));
if( $fileType != 'UTF-8'){
$string = mb_convert_encoding($string ,'utf-8' , $fileType);
}
return $string;
}
$content=mip_replace($content);

本文來源╃▩:http://www.kwsolidarity.com/news/show-1642.html
大狠狠大臿蕉香蕉大视频,人妻[21p]大胆,日韩精品无码去免费专区,少妇人妻偷人精品视频1出轨