Forum Moderators: coopster

Message Too Old, No Replies

How can i parse HTML and get/replace/modify tag attributes?

         

BlackDex

1:02 pm on Jan 17, 2007 (gmt 0)

10+ Year Member



Hello there,

I am currently trying to parse a HTML-String.
I want to get all tags and based on there attributes and its value, i want to add/modify attributes.

Now i tryed to use the DomDocument Class with PHP5.2.
This works kinda, but it changes the HTML more than i did/want.
It adds a!DOCTYPE and changes UTF8 texts into (wrong) entities.

Is there someway to disable these warnings and modifications?
Or
Is there an other way to do the same thing, but then without these checks.

Example HTML Content:


<div id="test1">
<div id="test2" class="testClass">
<span style="font-color: #900;" class="secondTestClass">
Testing<br>
</span>
ØøÅå_^{}\[~]¦ÆæßÉ@£$¥èéùìòÇ!"#¤%&'()*+,ÖÑܧ¿äöñüà-./:;<=>?¡Ä
</div>
</div>

Thx in advanced.

[edited by: BlackDex at 1:04 pm (utc) on Jan. 17, 2007]

eelixduppy

11:18 pm on Jan 17, 2007 (gmt 0)



Maybe a preg_replace [us3.php.net] is what you are looking for? Have the patterns and replacements in arrays.

Maybe I'm misunderstanding you with this, but if I am then the next recommendation would be to look at DHTML [w3.org], which it seems you've tried before.