/
获取调换文章中的路径
@param string ¥xstr 内容
@param string ¥keyword 创建照片的文件名
@param string ¥oriweb 网址
@return string
/
function replaceimg(¥xstr,¥keyword, ¥oriweb){
//保存路径
¥d = date(Ymd, time());
¥dirslsitss = /var/www/weblist/uploads/.¥keyword./.¥d;//分类是否存在
if(!is_dir(¥dirslsitss)) {
@mkdir(¥dirslsitss, 0777);
}
//匹配的src
preg_match_all(#<img.?src=([^])[^>]>#i, ¥xstr, ¥match);
foreach(¥match[1] as ¥imgurl){
¥imgurl = ¥imgurl;
if(is_int(strpos(¥imgurl, http))){
¥arcurl = ¥imgurl;
} else {
¥arcurl = ¥oriweb.¥imgurl;
}
¥img=file_get_contents(¥arcurl);
if(!empty(¥img)) {
//保存到办事器
¥fileimgname = time().-.rand(1000,9999)..jpg;
¥filecachs=¥dirslsitss./.¥fileimgname;
¥fanhuistr = file_put_contents( ¥filecachs, ¥img );
¥saveimgfile = /uploads/¥keyword./.¥d./.¥fileimgname;
¥xstr=str_replace(¥imgurl,¥saveimgfile,¥xstr);
}
}
return ¥xstr;
}