How can I retrieve the value of an input element using PHP DOMXPath?

To retrieve the value of an input element using PHP DOMXPath, you first need to load the HTML content into a DOMDocument object. Then, you can use DOMXPath to query for the input element and extract its value attribute. Finally, you can access the value of the input element using the DOMNodeList returned by the query.

// Load the HTML content into a DOMDocument object
$html = '<input type="text" value="example">';
$dom = new DOMDocument();
$dom->loadHTML($html);

// Use DOMXPath to query for the input element
$xpath = new DOMXPath($dom);
$input = $xpath->query('//input')->item(0);

// Retrieve the value of the input element
$value = $input->getAttribute('value');

echo $value; // Output: example