physaux Posted January 19, 2010 Share Posted January 19, 2010 Hello everyone, I am using DomDocument, to find <form>...</form> data, and my goal with it was to extract the information between the form tags. Here is my code so far: function gettag($pagedata, $tag){ $wasinloop = false; $foundgoodvalue = false; $dom = new DOMDocument; libxml_use_internal_errors(true); @$dom->loadHTML($pagedata); libxml_use_internal_errors(false); $xpath = new DOMXPath($dom); $aTag = $xpath->query('//'.$tag.''); $finaloutput = array(); foreach($aTag as $url){ $wasinloop = true; $nodevalue = $url->nodeValue; if($nodevalue == "" or $nodevalue == NULL){ $nodevalue = ""; }else{ $foundgoodvalue = true; } echo "[found a '".$tag."']"; $finalouput[] = array('content' => $nodevalue); } if($wasinloop == false or $foundgoodvalue == false){ $finaloutput[0]['content'] = ""; } return $finaloutput; } So as you can see, the $nodevalue should be all the information between form tags... which it is... kind of.. The data I get back is not the "HTML Version" of what was inbetween the tags, just the "text version". The "$nodevalue" does not keep the html structure, meaning the <input></input> tags dissapear and everything. I want to keep it all, I just want to "extract" what is inside of the form tags. But this program is destroying that html code. Could anyone advise me how I can fix this? Should I just use a preg match? That would get confusing because the form changes sometimes.. I thought this function should be able to do just this? Link to comment https://forums.phpfreaks.com/topic/189070-problems-with-using-domdocument-to-copy-forms-how-to-fix/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.