user13006535
user13006535

Reputation:

Echo tag value from HTML file in PHP file

I have this html file with this tag:

fileHTML.html

<input type="hidden" id="inputID" value="test">

Is it possible to echo the tag value (ie: "test") in an external PHP file ? This is where I am now.

filePHP.php

<?php                  
  $doc = new DOMDocument();
  $doc->loadHTMLFile("fileHTML.html");
  // echo the value in the input tag from $doc
?>

Upvotes: 0

Views: 37

Answers (1)

ArSeN
ArSeN

Reputation: 5248

Yes it is possible. For simplicity reasons I load the HTML from a string.

You first have to get the element and then the attribute value (which is called "value" in your example too).

$doc = new DOMDocument();
$doc->loadHTML('<input type="hidden" id="inputID" value="test">');
  
$element = $doc->getElementById('inputID');
var_dump($element->getAttribute('value')); // outputs: string(4) "test"

Upvotes: 1

Related Questions