I Just discovered domdocument and had previously been using regex..
I need to return the entire form element with all the inputs.
I don't need to create an entire document i just want that part, in a string that I can manipulate. I have been messing with the following chunk of code trying to make it do something useful, but so far, nothing.
Can anyone make sense of this before I go back to regex?
//get HTML into variable
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://www.openroadlending.com/Apply.aspx?aid=134');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$html=curl_exec($curl);
$dom = new domDocument;
@$dom->loadHTML($html);
$dom->preserveWhiteSpace=false;
$xpath = new DOMXPath($dom);
$body = $xpath->query('html/');
echo var_dump($body);
//echo $body->item(0);
$inputs = $xpath->getElementsByTagName('form');
// foreach($inputs as $in){
// $input = $in->saveHTML;
// //echo $input;
// }
DOMXPath
has no methodgetElementsByTagName
. You can get to the forms via several methodsgetElementsByTagName
XPath query
Once you have the form you're after (by selecting it from the
$forms
collection or by using a more specialised XPath query), you can get the HTML as a string usingyou can use this Function
and use like this
and You Can Use This function for Get Element By Class
and This function Is Not Related To This Question But It Useful