【发布时间】:2012-06-28 06:59:43
【问题描述】:
我正在尝试查找正则表达式,它将从 css 文件中提取所有路径。我已经搜索过,我能找到的只有这两个帖子,实际上似乎不起作用:
PHP - extract image paths from css
Why doesn't this PHP regular expression extract the url from the css value?
我想要得到的是这样的数组:
array(0 => 'image/header.gif', 1 => 'image/footer.png') etc.
知道提取它的正则表达式是什么 - 请记住,字符之间可能没有空格,或者 url() 的左括号和右括号之间也可能有额外的空格.
我正在使用以下内容来处理 css 并提取路径(但显然我没有正确的表达式来按照我想要的方式进行操作):
$images = array();
if (preg_match_all($regex, $cssContent, $matches)) {
$images = $matches[1];
}
【问题讨论】:
-
您的 css 文件中有示例吗?
-
嗨 Mellamokb - 任何 css 文件都可以 - 我正在尝试不同的网站和不同的 css 文件。
标签: php css regex background-image