/*
* ȡַеͼƬ
* $str һַ
* $f   ǷͼƬƵ$f=1 ͼƬ
*/
function getImages($str,$f="",$host="",$path="/"){
     if(preg_match("/<(IMG|img)(\s+|)(.*?)src(\s+|)=(\s+|)(||'|\"|)(\s+|)(.*?)(.jpg|.gif|.png|.bmp|.jpeg|.JPG|.GIF)(.*?)>/ies",$str,$rs)){
     $imgpath=$rs[8].$rs[9];
     if(strpos($imgpath,"http")!==0) {
         //жǷΪĿ¼ url
         $path1=strpos($imgpath,"../",0);
         while($path1!==false) {
             if(substr($path,strlen($path)-1,strlen($path))=="/") $path=substr($path,0,strlen($path)-1);
             $imgpath=substr($imgpath,strpos($imgpath,"../")+3,strlen($imgpath));    
         //     echo $imgpath.strripos($path,"/")."\n";    
             $path=substr($path,0,strripos($path,"/"));
             $path1=strpos($imgpath,"../",0);
         }
         if($path!='/') $imgpath = str_replace($path,"",$imgpath);
         if(strpos($imgpath,'/')!==0) $imgpath= str_replace("//","/",$path."/".$imgpath);
         $imgpath= str_replace("//","/",$imgpath);
         $imgpath=$host.$imgpath;
   	 }    
     //֤ͼƬԻ
     /*
     $size=getimagesize($imgpath);
     $w=(preg_match("/width=\"(.*?)\"/i",$size[3],$rsw))?$rsw[1]:0;
     $h=(preg_match("/height=\"(.*?)\"/i",$size[3],$rsh))?$rsh[1]:0;
     if($w>100 && $h>80){
     */
     //     echo "ͼƬ·:     ".$imgpath
    
     //ͼƬƵ
     if($f=="1"){
         $uppaths="";
         $dir=substr($host,(strripos($host,"//")+2),strlen($host));
         if(is_dir($uppaths)!=TRUE) mkdir($uppaths,0777);
         if(is_dir($uppaths."/".$dir)!=TRUE) mkdir($uppaths."/".$dir,0777);
         $name=substr($rs[8],(strripos($rs[8],"/",0)+1),strlen($rs[8]));    
         $name=$uppaths."/".$dir."/".$name.$rs[9];    
         if(copy($imgpath,$name));
         $imgpath=str_replace("../UserFiles","/UserFiles",$name);
     }    
     $imgpath=str_replace($rs[8].$rs[9],$imgpath,$rs[0]);
     $imgpath=str_replace("<","{",$imgpath);
     //}
     $str =str_replace($rs[0],$imgpath,$str);
     return getImages($str,$host,$path);
  }else{
     return   $str;
  }
}