[英]How to find all class names or ids from a CSS file that contains a background image using Regular expression and PHP?
[英]PHP - Regular expression to extract all paths to the images from within the CSS file
我正在尝试找到正则表达式,它将从css文件中提取所有路径。 我搜索了所有我能找到的这两个帖子,实际上似乎没有用:
我想得到的是这样的数组:
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文件中提取图像所有路径的表达式:
'/url\(\s*[\'"]?(\S*\.(?:jpe?g|gif|png))[\'"]?\s*\)[^;}]*?/i'
像这样的东西,我想:
/url\s*\(\s*['"]([^'"]+)['"]\s*\)/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.