Home  >  Article  >  Backend Development  >  PHP captures images in articles and replaces them locally (implementation code)_PHP tutorial

PHP captures images in articles and replaces them locally (implementation code)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:00:25826browse

Copy code The code is as follows:

/**
* Get the image path in the replacement article
* @param string $xstr content
* @param string $keyword The file name of the created 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 category exists
if(!is_dir($dirslsitss)) {
@mkdir($dirslsitss, 0777);
}

// Matching image's src
preg_match_all('#]*>#i', $xstr, $match);

foreach($match[1] as $imgurl){

$imgurl = $imgurl;

if(is_int(strpos($imgurl, 'http'))){
                                                           curl);

 
If(!empty($img)) {

//Save the image to the server
$fileimgname = time()."-".rand(1000,9999).".jpg";
                                                                                                                                                                                                                                                                                                    ."/".$fileimgname; > }





http://www.bkjia.com/PHPjc/328059.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/328059.html

TechArticle
Copy code The code is as follows: /** * Get the image path in the replacement article* @param string $xstr content* @param string $keyword The file name of the created photo* @param string $oriweb URL...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn