[英]CLeditor uses the HTML 'align' attribute. How can I change that to CSS 'text-align'?
[英]PHP: How to add a CSS text-align property to an already present inline style attribute of an element using simple_html_dom parser?
我有一個字符串變量$str
,其中包含頁面一部分的HTML。 我需要將CSS屬性text-align:justify
到HTML中的所有<p>
元素(最好使用simple_html_dom
解析器)。
一些<p>
元素已經具有內聯style
屬性,而其他一些則沒有。 所以我不能做這樣的事情
$str_html = str_get_html($str);
foreach ($str->find('p') as $p) {
$p->style='text-align:justify;';
}
因為這將使已經應用於<p>
元素的任何其他樣式無效。
PS:我無法使用JQuery。 我可以使用JS,但只能將其作為最后的手段。
您可以串聯而不是重新分配
$str_html = str_get_html($str);
foreach ($str->find('p') as $p) {
$p->style .= '; text-align:justify;';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.