有人想过在html标记上将css样式替换为样式属性吗?例如,您有css文件html文件。
css:
#示例{颜色:#CCC;字体重量:粗体;}
html:
当您运行php时,您将得到这个
为什么?为什么:)
有些工作需要一些不支持的系统或脚本标记的内联样式
示例:
电子邮件模板(所有的人都不能在电子邮件中插入,对吗?)
或在另一个系统中构建用于插入的HTML (产品详细信息在amazon.com中,.)
发布于 2011-03-29 18:22:01
您可能需要使用DOM解析器,看看SimpleHTMLDom。下面是一个例子:
// Assuming that it's an array of styles
// keyed by HTML element IDs or classes.
// @see http://www.google.com/search?q=php+css+parser
$styles = some_php_css_parser('example.css');
// Create a DOM object
$html = new simple_html_dom();
// Load HTML from a HTML file,
// there are also other options, @see API.
$html->load_file('test.htm');
// Walk through the target elements.
foreach ($html->find('blah') as $element) {
$element->style = $styles[$element->id];
}
// Cache and output...
另外,需要来考虑缓存输出,否则我也会这么说,但是为什么!
发布于 2011-03-29 18:09:13
爆炸css文件,解压属性\ css,在html中使用css来str_replace属性,但是为什么呢?
https://stackoverflow.com/questions/5481054
复制相似问题