tags:

views:

88

answers:

1

Hi,

Regular expressions are not my forte and could really do with assistance on matching and replacing the following:

In a HTML file I have many instances of HTML like this:

<font class=font8>text text text</font>

The font tag can have different content in either single word or multiple word with spaces and maybe numbers.

I need to find all instances of this and replace with:

<span class="bold">(text that was there)</span>

Thanks James

PS: the HTML was generated from word that is why it is so bad :o)

+4  A: 

Use getElementsByTagName('font') and the DOMDocument::loadHTML method and iterate through the nodelist based in the ->length, then createElement('span') and setAttribute for the class name value of bold, do a replaceChild to replace it.

Reference for DOM: http://php.net/manual/en/book.dom.php

meder
I cant seem to figure out how to use this. I can get as far as replaceChild but it does not work... for($i = 0; $i < $dom->getElementsByTagName('font')->length; $i++) { $newElement = $dom->createElement('span'); $dom->replaceChild($dom->getElementsByTagName('font')->item($i), $newElement);}
jodm