七牛CDN加速代码
function qiniu_cdn_replace($html){
$local_host = 'https://www.msbear.cn'; //博客域名
$qiniu_host = 'https://static.msbear.cn'; //七牛域名
$cdn_exts = 'js|css|png|jpg|jpeg|gif|ico|flv|tiff|bmp|mp3|wmv|wma|rmvb|rm|avi|txt|doc|docx|xls|xlsx|zip|rar|pdf|mp4'; //扩展名(使用|分隔)
$cdn_dirs = 'usr|admin'; //目录(使用|分隔)
$cdn_dirs = str_replace('-', '\-', $cdn_dirs);
if ($cdn_dirs) {
$regex = '/' . str_replace('/', '\/', $local_host) . '\/((' . $cdn_dirs . ')\/[^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
$html = preg_replace($regex, $qiniu_host . '/$1$4', $html);
} else {
$regex = '/' . str_replace('/', '\/', $local_host) . '\/([^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
$html = preg_replace($regex, $qiniu_host . '/$1$3', $html);
}
return $html;
}
- 阅读剩余部分 -