超碰免费人人操|国产视频二区久久艹人人操|欧美激情第一页在线|久热最新无码中文视频|91精品国际成人|亚洲成人精品在线视频青青草|久草免费高清完整在线观看|你懂的AV在线日本黄网页|国产黄色AV日韩女同网|欧美成人色区导航片av

php采集文章中的圖片獲取替換到本地實(shí)例

時間:2025-12-02 03:40:24 php語言

php采集文章中的圖片獲取替換到本地實(shí)例

  導(dǎo)語:PHP中如何把圖片替換到本地中,你知道這樣的程序要怎么寫嗎?以下的是對php采集文章中的圖片獲取替換到本地的實(shí)現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,有需要的朋友可以參考一下。

  代碼如下:

  /**

  * 獲取替換文章中的圖片路徑

  * @param string $xstr 內(nèi)容

  * @param string $keyword 創(chuàng)建照片的文件名

  * @param string $oriweb 網(wǎng)址

  * @return string

  *

  */

  function replaceimg($xstr,$keyword, $oriweb){

  /pic/p>

  $d = date('Ymd', time());

  $dirslsitss = '/var/www/weblist/uploads/'.$keyword.'/'.$d;/pic/p>

  if(!is_dir($dirslsitss)) {

  @mkdir($dirslsitss, 0777);

  }

  /pic/p>

  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)) {

  /pic/p>

  $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;

  }

【php采集文章中的圖片獲取替換到本地實(shí)例】相關(guān)文章:

php中fsockopen用法實(shí)例11-07

php獲取新浪微博數(shù)據(jù)API的實(shí)例代碼02-18

php多個文件及圖片上傳實(shí)例詳解01-23

php中return的用法實(shí)例分析10-12

php中獲取數(shù)組長度的方法12-01

php中實(shí)現(xiàn)回刪功能實(shí)例01-26

PHP中檢測ajax請求的代碼實(shí)例03-16

php畫圖實(shí)例09-15