0

I included an html file like this, so that it is not displayed when the site loads:

<div id="menugrp0" class="menuhide">
<?php include 'menugrp0.html';  ?>
</div>

Now I want it to be shown at a specific spot. I am using this php code, to get some variables which are transported with the $_SESSION. I am using this kind of question for some simple html links, in which case it works perfectly:

if ($_SESSION['gruppe'] == $h['gruppe']) {     
  printf(' menugrp0.html');
}

I know that this is not working at all at the moment for this included html. I also tried to add the <?php [...] ?> tag inside the printf, which is also not working.

Is it possible to show a hidden included html file with a printf tag?

pr0cz
  • 509
  • 7
  • 22
  • Just include it in the spot where you want the content shown instead? Seems a lot simpler. – Qirel Jan 03 '17 at 12:31
  • But there are like 4 different include files. Only the one should be shown, which matches with the `$_SESSION`. – pr0cz Jan 03 '17 at 12:31
  • Then use a condition to only load the file which is needed instead? `if ($_SESSION['gruppe'] == $h['gruppe']) { include 'menugrp0.html'; }`? – Qirel Jan 03 '17 at 12:32
  • 4
    Please do not use `include` for this, but `echo file_get_contents('menugrp0.html');` – Daan Meijer Jan 03 '17 at 12:33
  • 3
    Alternatively store it in a variable, but then the content of that file needs to be returned, see example 5 http://php.net/manual/en/function.include.php – Qirel Jan 03 '17 at 12:34

3 Answers3

0

Try this one.

<?php
if($_SESSION['gruppe'] == $h['gruppe']){
    echo 'Foo';
    include ('/path/to/menugrp0.html');
    echo 'Example: one';
}

?>
shin
  • 31,901
  • 69
  • 184
  • 271
0
readfile('menugrp0.html'); // Reads a file and writes it to the output buffer. It is like read then "echo"

How to echo the whole content of an .html file in php?

Community
  • 1
  • 1
nggit
  • 611
  • 8
  • 8
0

Thanks to Daan Meijer, this works.

  echo file_get_contents('...');    
                    }
Community
  • 1
  • 1
pr0cz
  • 509
  • 7
  • 22