I want to use a variable inside an HTML-String of another PHP-File template.php
in my PHP-File constructor.php
.
I´m searched on Stackoverflow for a workaround to include the content of the other PHP-File. I included the following code into constructor.php
because its known to be more safe instead of using file_get_contents();
Source:
function requireToVar($file){
ob_start();
require($file);
return ob_get_clean();
}
The rest of constructor.php
looks like this:
...
$sqli = mysqli_query($mysqli, "SELECT ...");
if(mysqli_num_rows($sqli) > 0){
$ii = 0;
while ($row = $sqli->fetch_assoc()) {
$ii++;
if($row['dummy']=="Example"){
$content.=requireToVar('template.php');
...
The template.php
looks like this:
<?php echo "
<div class='image-wrapper' id='dt-".$row['id']."' style='display: none;'>
...
</div>
"; ?>
The constructor.php
doesn´t recognize the var $row['id']
inside the string of template.php
as its own variable and also doesn´t execute it. The variable definitely works for the other code in constructor.php
.
If I´m copy&paste the code of template.php
into constructor.php
after $content.=
its working like a charm. But I want to restructure my constructor.php
because its getting to big and this way its easier to customize.
I don´t know how to describe this problem more exactly, but I´m hoping this title fits to my problem.