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.