I have a php file with the following code:
echo($x);
Which simply prints
5.0
How would I display this value in a html file?
I have a php file with the following code:
echo($x);
Which simply prints
5.0
How would I display this value in a html file?
You can use any HTML manipulation APIs, like DOMDocument
class. But, just to get you started, I assume you have a very simple HTML file:
<html><head></head><body></body></html>
And you want to put the value of the $x
variable inside the <body>
tag using a <div>
tag; simply:
<?php
$dom = new DOMDocument;
$HTML_file = "paht/to/your/file.html";
$dom->loadHTMLFile($HTML_file);
// To get the <body> tag in the HTML file
$xpath = new DOMXPath($dom);
$body = $xpath->query('//body')->item(0);
// Insert some tags inside the <body> tag
$x = 5;
$element = $dom->createElement('div', $x);
$body->appendChild($element);
// overwrites to the same file
$dom->saveHTMLFile($HTML_file);
?>