试试这个尺寸。它不适用于以开头的字符串,url(
但如果您正在解析实际的 CSS,那么在没有选择器或属性的情况下开始是无效的。
$data =' #foo { background: url("hello.jpg"); } #bar { background: url("flowers/iris.png"); }';
$output = array();
foreach(explode("url(", $data) as $i => $a) { // Split string into array of substrings at boundaries of "url(" and loop through it
if ($i) {
$a = explode(")", $a); // Split substring into array at boundaries of ")"
$url = trim(str_replace(array('"',"'"), "", $a[0])); // Remove " and ' characters
array_push($output, $url);
}
}
print_r($output);
输出:
Array ( [0] => hello.jpg [1] => flowers/iris.png )