<div style = "text-align:left;" class="ref"> Text </div>
I want to replace <div>
with <p>
without losing attributes.
Any help is appreciated.
tag using php
<div style = "text-align:left;" class="ref"> Text </div>
I want to replace <div>
with <p>
without losing attributes.
Any help is appreciated.
Try This:
$str = '<div style = "text-align:left;" class="ref"> Text </div>';
$newstr = preg_replace('/<div [^<]*?class="([^<]*?ref.*?)">(.*?)<\/div>/','<p class="$1">$2</p>',$str);
echo $newstr;
Output : <p class="ref"> Text </p>