This article is to the PHP collection article in the picture to get replaced with the local implementation code for a detailed analysis of the introduction, the need for a friend reference
Copy CodeThe code is as follows:
/**
* Get the picture path in the replacement article
* @param string $xstr content
* @param string $keyword Create a file name for the photo
* @param string $oriweb URL
* @return String
*
*/
function replaceimg ($xstr, $keyword, $oriweb) {
Save path
$d = Date (' Ymd ', Time ());
$DIRSLSITSS = '/var/www/weblist/uploads/'. $keyword. ' /'. $d;//whether the classification exists
if (!is_dir ($DIRSLSITSS)) {
@mkdir ($DIRSLSITSS, 0777);
}
Matching images of SRC
Preg_match_all (' #]*> #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)) {
Save picture to Server
$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;
}
http://www.bkjia.com/PHPjc/372548.html www.bkjia.com true http://www.bkjia.com/PHPjc/372548.html techarticle This article is to the PHP collection article in the picture to get replaced with the local implementation code for a detailed analysis of the introduction, the need for a friend reference under the copy Code code as follows:/** * Get replacement ...