Nolongerused3921 Posted April 16, 2008 Share Posted April 16, 2008 Currently I'm trying to figure out how to take a small bit of html, say <input name="tesT" value="YAY" /> or <input name="tesT" value="YAY"> or <textarea name="moo">blah</textarea> Edit, say, the value (Or innerHTML), an attribute or two, add an attribute, take one out, etc... Then export it back the same way it came in, but with the modifications. But I'm having two problems that are annoying me to no end. 1) I don't usually work with DOM, so I'm not quite sure how to edit attributes and the like. The HTML aspect isn't well documented, so any help here would be nice. 2) I'm getting extremely annoyed by the fact saveHTML() AND saveXML() both add all the extra stuff that I don't want. What's worse, it looks like even by importing the HTML with loadHtml, it adds the body tags which I don't need or want. How do I get around this? I want JUST the element(s) that go in, to come out. $domdoc = new DOMDocument(); $domdoc->validateOnParse = false; $domdoc->loadHtml($element); $textarea = $domdoc->getElementsByTagName("textarea"); $xml = simplexml_import_dom($domdoc); PrintNeatArrays($xml); This is pretty much all I have right now. Any help would be appreciated, thanks. Link to comment https://forums.phpfreaks.com/topic/101446-working-with-dom-html/ Share on other sites More sharing options...
Nolongerused3921 Posted April 17, 2008 Author Share Posted April 17, 2008 Could use some help. Link to comment https://forums.phpfreaks.com/topic/101446-working-with-dom-html/#findComment-519254 Share on other sites More sharing options...
haku Posted April 17, 2008 Share Posted April 17, 2008 Since your questions are really broad and general, its hard to answer them. I mean, what exactly do you want? It doesn't sound like you are having a specific problem, but rather just don't really understand how to use XML with PHP very well. Teaching you how to use PHP and XML is beyond the scope of one thread, especially seeing as this thread is in the 'help' section, and not the 'tutorials' section. Maybe this can help you out: http://www.google.com/search?hl=en&safe=off&q=php+and+xml&btnG=Search Link to comment https://forums.phpfreaks.com/topic/101446-working-with-dom-html/#findComment-519259 Share on other sites More sharing options...
Nolongerused3921 Posted April 17, 2008 Author Share Posted April 17, 2008 1) How do you edit attributes using PHP's Dom, with imported html. 2) How do you import/export html into PHP's Dom, without adding declarations or extra html tags. Link to comment https://forums.phpfreaks.com/topic/101446-working-with-dom-html/#findComment-519573 Share on other sites More sharing options...
Nolongerused3921 Posted April 18, 2008 Author Share Posted April 18, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/101446-working-with-dom-html/#findComment-520456 Share on other sites More sharing options...
Veehmot Posted June 22, 2008 Share Posted June 22, 2008 haku: I think his problem is specific. The one that don't understand is you. I'm also getting annoyed by the mode that DOM Functions in PHP validate content. Example: I want to parse a website, and I know that a <p> tag with the "id" attribute set to "caption" holds user input. But the user input can be ANYTHING, including those '<' and '>' characters (no htmlentities(), of course). So, if I get the HTML: <html> <head> </head> <body> <p id="caption">hi guyzzzz my name iz h4x0000r and my clan tag iz <1337> soo im <1337>h4x0000r =)</p> </body> </html> I can use the C14N() method to get raw data from a node, but the problem it's when i use loadHTML() method. That method adds some extra information, and parses the tag <1337>, to something like: <html> <head> </head> <body> <p id="caption">hi guyzzzz my name iz h4x0000r and my clan tag iz <1337> soo im <1337>h4x0000r =)</1337></1337></p> </body> </html> It adds the closing tags. Yes, correct form would be to change <1337> to </1337>, but user doesn't know this. And the web-site doesn't use htmlentities(), (yes, tags are not displayed in screen, you can only see them in source code). So, how can I get the REAL raw data? I mean <p id="caption">hi guyzzzz my name iz h4x0000r and my clan tag iz <1337> soo im <1337>h4x0000r =)</p> Instead of <p id="caption">hi guyzzzz my name iz h4x0000r and my clan tag iz <1337> soo im <1337>h4x0000r =)</1337></1337></p> Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/101446-working-with-dom-html/#findComment-571303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.