繁体   English   中英

如何使用正则表达式和 PHP 从包含背景图像的 CSS 文件中查找所有类名或 ID?

[英]How to find all class names or ids from a CSS file that contains a background image using Regular expression and PHP?

我想使用 PHP 的正则表达式从文本中获取类名或 ID。

例如:

.vc_custom_1547091583528{
    margin-bottom:40px!important;
    padding-top:7rem!important;
    padding-bottom:1rem!important;
    background:#092746 url(http://icoachu.us/wp- 
    content/uploads/2016/12/princeton.jpg?id=957)!important;
    background-position:center!important;
    background-repeat:no-repeat!important;
    background-size:cover!important
}

这是 css,输出应该是:

array(0=>".vc_custom_1547091583528");

并且

array(0 => "http://icoachu.us/wp-content/uploads/2016/12/princeton.jpg?id=957")

所以它们将是两个不同的功能。

最后我找到了正确的答案。 正则表达式可以变得更智能和更短,但现在这个工作得很好。

([.#][a-zA-Z0-9_-]*?){[a-zA-Z0-9~;:#! _-]*\(['"]?(.*?)['"]?\)[a-zA-Z0-9~;:#! _-]*}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM