PHP - how to load HTML files?
At the moment I have such a file
<?php
if(some condition)
{
//Dont allow access
}
else
{
echo "<html>My HTML Code</html>";
}
?>
But I wanted to do something like this to keep my php file short and clean.
<?php
if(some condition)
{
//Dont allow access
}
else
{
//print the code from ..html/myFile.html
}
?>
How can i achieve this?
you can take a look at PHP Simple HTML DOM Parser seems like a good idea for your needs! Example:
// Create a DOM object from a string
$html = str_get_html('<html><body>Hello!</body></html>');
// Create a DOM object from a URL
$html = file_get_html('http://www.google.com/');
// Create a DOM object from a HTML file
$html = file_get_html('test.htm');
save your html content as a separate template and just include it
<?php
if(some condition)
{
//Dont allow access
}
else
{
include ("your_file.html");
}
?>
OR
<?php
if(some condition)
{
//Dont allow access
}
else
{
readfile("your_file.html");
}
?>
readfile faster and less memory than file_get_contents
<?php
if(some condition)
{
//Dont allow access
}
else
{
echo file_get_contents("your_file.html");
}
?>
, nauphal , include()
, , (, , )
1:
ob_start();
include "yourfile.html";
$return = ob_get_contents();
ob_clean();
echo $return;
2: templaters, CTPP, Smarty .. Templaters php , , CTPP:
$Templater -> params('ok' => true);
$Template -> output('template.html');
html:
<TMPL_if (ok) >
ok is true
<TMPL_else>
ok not true
</TMPL_if>
. Templaters , .