I want to convert my html strings which contain <p style=“text-align:center; others-style:value;”>Content</p>
to <center>Content</center>
, and <p style=“text-align:right; others-style:value;”>Content</p>
to <right>Content</right>
etc.
My previous question has an answer which can achieve this perfectly. Which is regex is:
$RegEx = '/<(.*)(text-align:)(.*)(center|left|right|justify|inherit|none)(.*)(\"|\”|\'|\’)>(.*)(<\/.*)/s';
$string = preg_replace($RegEx, '<$4>$7</$4>', $string);
However, my strings may contain more than one occurrences of the text-align. For example, I might have <div style=‘text-align:left; others-style:value;’ class=‘any class’>Any Content That You Wish</div><p style=“text-align:center; others-style:value;”>Content</p>
I want it to become <left>Any Content That You Wish</left><center>Content</center>
, but it would just output <center>Content</center>
.
How can I get what I want in PHP? Many thanks.