Files
2024_WEBSITE_fipf/plugins/fipfcard_plugin/php/utils/create_html.php
2024-02-12 10:13:02 +01:00

40 lines
1.1 KiB
PHP

<?php
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@param two arguments :
1. html files to include in front
- can be a string of 1 filename
- or an array of strings of filenames
( https://stackoverflow.com/q/4747876/9497573 )
- it's probably better to only add 1 file, and let it include other files
2. list of variables to make available to this files
- in the form of key => val
- recommanded to do it with compact()
ex: create_html( "file.html", compact("var1","var2",) );
ex: create_html( array("file1.html", "file2.html"), array("var1"=>"value") );
@return a string of html code
using ob_start() and ob_get_clean()
allows to have php expansion inside the html loaded
in opposition to the methode file_get_contents()
https://stackoverflow.com/a/4402045/9497573
*/
function create_html($files, $vars = null) {
$files = (array)$files;
$html_dir = FIPFCARD_PLUGIN_DIR.'html/';
if (!is_null($vars))
extract($vars);
ob_start();
foreach($files as $file) {
include($html_dir.$file);
}
$html = ob_get_clean();
return $html;
}
?>