$dom = new DOMDocument(); $dom->loadHTML(''); $form = $dom->getElementsByTagName('form')->item(0); $action = $form->getAttribute('action'); echo $action; // output: submit.php
$xml = 'The DOMNode getAttribute() function is a part of the PHP DOM extension.'; $dom = new DOMDocument(); $dom->loadXML($xml); $book = $dom->getElementsByTagName('book')->item(0); $id = $book->getAttribute('id'); echo $id; // output: 123 Book Title