需要正则表达式来解析HTML标签[重复]

This question already has an answer here:

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)

</div>

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