PHP:如何使用simple_html_dom解析器将CSS text-align属性添加到元素的已存在的内联样式属性中?

I have a string variable $str which contains HTML for a part of a page. I need to add the CSS property text-align:justify to all the <p> elements in the HTML (preferably using simple_html_dom parser).

Some of the <p> elements already have an inline style attribute, others don't. So I can not do something like

$str_html = str_get_html($str);
foreach ($str->find('p') as $p) {
  $p->style='text-align:justify;';
}

Because this will void any other styles already applied to the <p> element.

PS:- I can not use JQuery. I can use JS but will only use it as a last resort.

查看全部
donqo88682
donqo88682
2014/09/27 14:54
  • css
  • php
  • html
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复