我需要获取 css 类名、属性和值,以便将内联 css 样式应用于 div。目前,我可以从这样的字符串中检索 css 类名信息:
$class = ".custom_class {
margin-top: 0px !important;
border-top-width: 0px !important;
border-right-width: 0px !important;
border-left-width: 0px !important;
padding-top: 250px !important;
padding-bottom: 250px !important;
background-image: url(http://localhost/wordpress/wp-content/uploads/2015/01/old-car.jpg?id=3663) !important;
border-left-color: #dd3333 !important;
border-right-color: #dd3333 !important;
border-top-color: #dd3333 !important;
}";
如何获取或正则表达式所有 css 属性和值,以便将它们包含在这样的 div 中:
<div class="custom_class" style="margin-top: 0px !important;border-top-width: 0px !important;border-right-width: 0px !important;border-left-width: 0px !important;padding-top: 250px !important;padding-bottom: 250px !important;background-image: url(http://localhost/wordpress/wp-content/uploads/2015/01/old-car.jpg?id=3663) !important;border-left-color: #dd3333 !important;border-right-color: #dd3333 !important;border-top-color: #dd3333 !important;"></div>
我试过这个:preg_match("/{(.*?)}/", $class, $match);
但它用括号输出。对于班级名称,我不知道该怎么做。