首先第一步,找到你修改的模塊,我以資訊模塊為例:路徑為:/module/article/show.inc.php然后打開,大概在18行左右 插入一下代碼,進行正則替換function mip_replace($content = ''){$pattern1 = "#<img.*?src=['\"](.*?)['\"].*?>...
首先第一步,找到你修改的模塊,我以資訊模塊為例:
路徑為:/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=https://www.ycwebs.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);