function img($url=''){
if( $url ){
$url = base64_decode($url);
$dir = pathinfo($url);
$host = $dir['dirname'];
$refer = $host.'/';
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_REFERER, $refer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$ext = strtolower(substr(strrchr($url,'.'),1,10));
$types = array(
'gif'=>'image/gif',
'jpeg'=>'image/jpeg',
'jpg'=>'image/jpeg',
'jpe'=>'image/jpeg',
'png'=>'image/png',
);
$type = $types[$ext] ? $types[$ext] : 'image/jpeg';
header("Content-type: ".$type);
echo $data;
}
}
function get_img( $str='' ){
if( $str ){
$preg_s = '/(src=\")(.*?)(\")/is';
$preg_bd = '/(baidu)/is';
if(preg_match_all($preg_s,$str,$arr) and preg_match_all($preg_bd,$str)){
foreach($arr[2] as $y){
if( preg_match_all( $preg_bd,$y ) ){
$url = base64_encode($y);
$url = str_replace('=','',$url);
$str = str_replace($y,site_url("index/img/$url"),$str);
}
}
}
return $str;
}
}
$r['body'] = $this->hp->get_img( $r['body'] );