开发者

What's the best way to extract links to images from CSS files with PHP?

开发者 https://www.devze.com 2023-03-19 06:25 出处:网络
I want 开发者_运维技巧to find all links to images from a CSS file. E.g. background-image: url(images/abc123.jpg);

I want 开发者_运维技巧to find all links to images from a CSS file.

E.g.

background-image: url(images/abc123.jpg);

I've found a PHP class called CSS parser but it doesn't seem to have a very large API. Is there a better CSS parser about?

I need to be able to modify the links in the file after I have extracted them too.

Thanks.


function getImageUrls($input_string) {
   $matches = array();
   preg_match_all('/url\((.+?)\);/i', $input_string, $matches);
   return preg_replace('/url\((.+?)\);/i', '$1', $matches);
}

something like that anyways. pull the matches out and then format them to keep only the url path.

0

精彩评论

暂无评论...
验证码 换一张
取 消