我试着从css文件中获得这个信息:
url(/myServer/img/mosaico.png)我试着用这个:
preg_match_all('/url\((["\']?)((?!["\']?[data:]?).*?\.(gif|png|jpg|jpeg|svg|woff|eot|ttf))\\1\)?/i', $content, $matches, PREG_SET_ORDER))但是它不工作属性,表达式只捕获一些事件。有什么问题吗?
我还需要定期显示括号中的部件,如下所示:
array(
(int) 0 => 'url(/img/arrow-top-white.png)',
(int) 1 => '',
(int) 2 => '/img/arrow-top-white.png',
(int) 3 => 'png'
)发布于 2014-09-29 16:32:56
您可以使用下面的正则表达式来匹配上面提到的所有字符串。
url\(((?:\/[^\/()]+?)+?\.(gif|png|jpg|jpeg|svg|woff|eot|ttf))[^)]*\)演示
<?php
$content = "url(/myServer/img/mosaico.png)";
preg_match_all('~url\(((?:\/[^\/]+)+\.(gif|png|jpg|jpeg|svg|woff|eot|ttf))\)~', $content, $matches, PREG_SET_ORDER);
print_r($matches);
?>输出:
Array
(
[0] => Array
(
[0] => url(/myServer/img/mosaico.png)
[1] => /myServer/img/mosaico.png
[2] => png
)
)https://stackoverflow.com/questions/26104488
复制相似问题