[ create a new paste ] login | about

Link: http://codepad.org/bIyAlXUf    [ raw code | output | fork ]

PHP, pasted on Oct 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$dom = new DOMDocument;
@$dom->loadHTML('<body style=""><p class="Normal" style="direction:ltr;unicode-bidi:normal;"><span class="Normal-H"><span class="-H" style="font-weight:bold;"></span><span class="-H" style="font-weight:bold;">Some bold text</span></span></p><p class="Normal" style="direction:ltr;unicode-bidi:normal;"><span class="Normal-H"><span class="-H" style="font-style:italic;"></span><span class="-H" style="font-style:italic;">Some italic text</span></span></p></body></html>');
$xPath = new DOMXPath($dom);
$spans = $xPath->query('//span');
foreach($spans as $span){
  if($span->hasAttribute('style')){
    if(strstr($span->getAttribute('style'), 'font-weight:bold') !== FALSE){
      $newSpan = $dom->createElement('strong', $span->nodeValue);
      $span->parentNode->replaceChild($newSpan, $span);
    }
  }
}
echo $dom->saveHTML();


Output:
1
2
3
4
5
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body style="">
<p class="Normal" style="direction:ltr;unicode-bidi:normal;"><span class="Normal-H"><strong></strong><strong>Some bold text</strong></span></p>
<p class="Normal" style="direction:ltr;unicode-bidi:normal;"><span class="Normal-H"><span class="-H" style="font-style:italic;"></span><span class="-H" style="font-style:italic;">Some italic text</span></span></p>
</body></html>


Create a new paste based on this one


Comments: