PHP capture pictures in the article get replaced by local _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.