茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    php采集內(nèi)容中帶有圖片地址的遠(yuǎn)程圖片并保存的方法
    來源:易賢網(wǎng) 閱讀:950 次 日期:2015-03-31 11:21:21
    溫馨提示:易賢網(wǎng)小編為您整理了“php采集內(nèi)容中帶有圖片地址的遠(yuǎn)程圖片并保存的方法”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了php采集內(nèi)容中帶有圖片地址的遠(yuǎn)程圖片并保存的方法,可實現(xiàn)采集并保存遠(yuǎn)程圖片的功能,是非常實用的技巧,需要的朋友可以參考下

    本文實例講述了php采集內(nèi)容中帶有圖片地址的遠(yuǎn)程圖片并保存的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

    代碼如下:

    function my_file_get_contents($url, $timeout=30) {

    if ( function_exists('curl_init') )

    {

    $ch = curl_init();

    curl_setopt ($ch, curlopt_url, $url);

    curl_setopt ($ch, curlopt_returntransfer, 1);

    curl_setopt ($ch, curlopt_connecttimeout, $timeout);

    $file_contents = curl_exec($ch);

    curl_close($ch);

    }

    else if ( ini_get('allow_url_fopen') == 1 || strtolower(ini_get('allow_url_fopen')) == 'on' )

    {

    $file_contents = @file_get_contents($url);

    }

    else

    {

    $file_contents = '';

    }

    return $file_contents;

    }

    代碼如下:

    function get_remote($body,$title){

    $img_array = array();

    $img_path = realpath("../../../upfile/news/").'/'.date("y/m/d/"); //采集遠(yuǎn)程圖片保存地址

    //die($img_path);

    $img_rpath='/upfile/news/'.date("y/m/d/"); //設(shè)置訪問地址

    $body = stripslashes(strtolower($body));

    preg_match_all("/(src|src)=["|'| ]{0,}();

    $img_array = array_unique($img_array[2]);

    foreach ($img_array as $key => $value) {

    $get_file = my_file_get_contents($value,60);

    $filetime = time();

    $filename = date("ymdhis",$filetime).rand(1,999).'.'.substr($value,-3,3);

    if(emptyempty($get_file)){

    @sleep(10);

    $get_file = my_file_get_contents($value,30);

    if(emptyempty($get_file)){

    $body = preg_replace("/".addcslashes($value,"/")."/isu", '/notfound.jpg', $body);

    continue;

    }

    }

    if(!emptyempty($get_file) ){

    if( mkdirs($img_path) )

    {

    $fp = fopen($img_path.$filename,"w");

    if(fwrite($fp,$get_file)){

    $body = preg_replace("/".addcslashes($value,"/")."/isu", $img_rpath.$filename, $body);

    }

    fclose($fp);

    @sleep(6);

    }

    }

    }

    $body =str_replace("<img","<img ",$body);

    return $body;

    }

    function mkdirs($dir)

    {

    if(!is_dir($dir)){

    if(!mkdirs(dirname($dir))){

    return false;}

    if(!mkdir($dir,0777)){

    return false;}

    }

    return true;

    }

    //用法如下:

    $str ='fasfsdafsa<img src=http://filesimg.xxxx.com/2010/03/2010062300391582.jpg />';

    echo get_remote($str,'圖片');

    希望本文所述對大家的php程序設(shè)計有所幫助。

    更多信息請查看IT技術(shù)專欄

    更多信息請查看網(wǎng)絡(luò)編程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)