Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP替换背景图像url_Php_Css_Replace - Fatal编程技术网

PHP替换背景图像url

PHP替换背景图像url,php,css,replace,Php,Css,Replace,我想接收所有的背景图像url链接的能力,以改变他们。例如,仅修改本地链接 from this css: #img1 { background-image: url('http://someurl.com/someimg.png'); } #img2 { background-image: url('images/bg2.jpg'); } to this css: #img1 { background-image: url('http://someurl.com/someimg.png');

我想接收所有的背景图像url链接的能力,以改变他们。例如,仅修改本地链接

from this css:
#img1 { background-image: url('http://someurl.com/someimg.png'); }
#img2 { background-image: url('images/bg2.jpg'); }


to this css:
#img1 { background-image: url('http://someurl.com/someimg.png'); }
#img2 { background-image: url('somefolder/images/bg2.jpg'); } /* <- modified */

您可以使用
preg\u match\u all
功能:

$css = file_get_contents($file);
echo $css;
preg_match_all("/background-image: url\('(.*)'/", $css, $arr);
$images = $arr[1];

您是对的,它必须具有http:
$css = file_get_contents($file);
echo $css;
preg_match_all("/background-image: url\('(.*)'/", $css, $arr);
$images = $arr[1];