假设我们的$plain_css
变量中有一些 CSS:
.slide-pause {
cursor: url(http://example.com/img/bg/pause.png),url(http://example.com/img/bg/pause.png),auto;
}
.something {
background-image: url('http://example.com/img/bg/beautiful.png'); // We have Quotes here
}
我需要从此 CSS 获取所有 URL。
这就是我试图实现这一目标的方式:
preg_match_all('!url\(\'?http://example.com/.*\)!', $plain_css, $matches);
什么$matches
返回:
array
0 =>
array
0 => string 'url(http://example.com/img/bg/pause.png),url(http://localhost/site/img/bg/pause.png)'
1 => string 'url(http://example.com/img/bg/beautiful.png)'
我需要它返回:
array
0 => string 'url(http://example.com/img/bg/pause.png)'
1 => string 'url(http://example.com/img/bg/pause.png)'
2 => string 'url(http://example.com/img/bg/beautiful.png)'