php将图片本地化代码示例
注明:本网站来至www.php186.com
<?php
set_time_limit(0);
$styleFileContent = file_get_contents('article.css');
//note 匹配出需要下载的URL地址
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);
$imagesURLArray = array_unique($imagesURLArray[1]);
foreach($imagesURLArray as $imagesURL) {
$imagesURL = 'http://www.php186.com'.str_replace('"','',$imagesURL);
file_put_contents('img/'.basename($imagesURL), file_get_contents($imagesURL));
}
注明:本网站来至www.php186.com
<?php
set_time_limit(0);
$styleFileContent = file_get_contents('article.css');
//note 匹配出需要下载的URL地址
preg_match_all("/url\((.*)\)/", $styleFileContent, $imagesURLArray);
$imagesURLArray = array_unique($imagesURLArray[1]);
foreach($imagesURLArray as $imagesURL) {
$imagesURL = 'http://www.php186.com'.str_replace('"','',$imagesURL);
file_put_contents('img/'.basename($imagesURL), file_get_contents($imagesURL));
}
本文介绍了一种使用PHP实现图片本地化的技术方案。通过解析CSS文件中的URL,并使用file_get_contents()函数下载远程图片到本地目录,实现了资源的本地化处理。
262

被折叠的 条评论
为什么被折叠?



