我拼命想弄清楚如何从特定的字符串中获取所有路径和文件名。
ex.g。
src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.0.1') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff?v=4.0.1') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.0.1') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.0.1#fontawesomeregular') format('svg');
应该生成一个包含:
的数组../fonts/, fontawesome-webfont.eot?#iefix&v=4.0.1
../fonts/, fontawesome-webfont.woff?v=4.0.1
../fonts/, fontawesome-webfont.ttf?v=4.0.1
../fonts/, fontawesome-webfont.svg?v=4.0.1#fontawesomeregular
到目前为止我所遵循的是正则表达式:
url\(\'(.*?)\/(.*?)\'
问题在于我得到了以下内容:
.., /fonts/fontawesome-webfont.eot?v=4.0.1
.., /fonts/fontawesome-webfont.woff?v=4.0.1
.., /fonts/fontawesome-webfont.ttf?v=4.0.1
.., /fonts/fontawesome-webfont.svg?v=4.0.1#fontawesomeregular
那么,为了获得路径中最后一次出现,我需要考虑什么?
谢谢你的帮助, P
答案 0 :(得分:0)
这应该有效:
$s = "src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.0.1') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff?v=4.0.1') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.0.1') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.0.1#fontawesomeregular') format('svg');";
if (preg_match_all("~url *\('(\.\./fonts/)(.*?)'\)~i", $s, $arr)) {
print_r($arr[1]);
print_r($arr[2]);
}
<强>输出:强>
Array
(
[0] => ../fonts/
[1] => ../fonts/
[2] => ../fonts/
[3] => ../fonts/
)
Array
(
[0] => fontawesome-webfont.eot?#iefix&v=4.0.1
[1] => fontawesome-webfont.woff?v=4.0.1
[2] => fontawesome-webfont.ttf?v=4.0.1
[3] => fontawesome-webfont.svg?v=4.0.1#fontawesomeregular
)
答案 1 :(得分:0)
我在这里测试https://www.debuggex.com/并且它有效:
([.][.].?)\/(.*?)\'
答案 2 :(得分:0)