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

WBOY
Release: 2016-07-21 15:00:25
Original
825 people have browsed it

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...

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!