Heim  >  Artikel  >  php教程  >  php正则表达式之正则字符中的图片地址

php正则表达式之正则字符中的图片地址

WBOY
WBOYOriginal
2016-06-08 17:24:54934Durchsuche

本文章介绍了关于php正则表达式之正则字符中的图片地址,有需要的朋友可以参考一下。

<script>ec(2);</script>
 代码如下 复制代码

if (preg_match_all("/http://[^ "']+[.jpg|.gif|.jpeg|.png]+/ui",stripcslashes($content),$aliurl)){
$i=0; //多个文件++
while(list($key ,$v) = each($aliurl[0])){
//echo $v."
";
$filetype = pathinfo($v, PATHINFO_EXTENSION); //获取后缀名
$ff = @file_get_contents($v); //获取2进制文件内容
if(!stripos($v,"lao8.org")){//判断是否是自己网站下的图片
if (!empty($ff)){ //获取到文件就执行下面的操作
$dir = "upload/".date("Ymd")."/";//指定新的存储路径
if (!file_exists($dir)){//判断目录是否存在
@mkdir($dir,511,true); //创建多级目录,511转换成十进制是777具有可执行权限
}
$nfn = $dir.date("Ymdhis").$i.".".$filetype; //构建文件的新名字
$nf = @fopen($nfn,"w"); //创建文件
fwrite($nf,$ff); //写入文件
fclose($nf); //关闭文件
$i++; //多文件++
echo "php正则表达式之正则字符中的图片地址";
$content = str_replace($v,$nfn, $content);//替换content中的参数
}else{//获取不到图片则替换为默认图片
$content = str_replace($v,http://www.111cn.net/banner/banner.gif, $content);//替换content中的参数
}
}
}
}
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn