[英]How to find all class names or ids from a CSS file that contains a background image using Regular expression and PHP?
I want to get the class name or the ID from a text using regular expression with PHP.我想使用 PHP 的正则表达式从文本中获取类名或 ID。
For Instance:例如:
.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
}
This is css and the output should be:这是 css,输出应该是:
array(0=>".vc_custom_1547091583528");
and also并且
array(0 => "http://icoachu.us/wp-content/uploads/2016/12/princeton.jpg?id=957")
So they will be two different functions.所以它们将是两个不同的功能。
Finally I have found the right answer.最后我找到了正确的答案。 The regular expression can be made more smarter and short but right now this one works just fine.正则表达式可以变得更智能和更短,但现在这个工作得很好。
([.#][a-zA-Z0-9_-]*?){[a-zA-Z0-9~;:#! _-]*\(['"]?(.*?)['"]?\)[a-zA-Z0-9~;:#! _-]*}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.