使用PHP从CSS文件中提取图像的链接的最好方法是什么? [英] What's the best way to extract links to images from CSS files with PHP?
本文介绍了使用PHP从CSS文件中提取图像的链接的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要找到来自CSS文件的图片的所有链接。
I want to find all links to images from a CSS file.
例如
background-image: url(images/abc123.jpg);
我发现了一个名为 CSS解析器,但它似乎没有一个非常大的API。有更好的CSS解析器吗?
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.
谢谢。
推荐答案
function getImageUrls($input_string) {
$matches = array();
preg_match_all('/url\((.+?)\);/i', $input_string, $matches);
return preg_replace('/url\((.+?)\);/i', '$1', $matches);
}
拉出匹配,然后格式化它们只保留url路径。
something like that anyways. pull the matches out and then format them to keep only the url path.
这篇关于使用PHP从CSS文件中提取图像的链接的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文