-2
<?php 
    if ($Mobiel == "ja") {
    print "<font size='3vw'>";}
?>

This code works fine in a php-page (page.php) I use.
The output is:

<font size='3vw'>

I want part of this page echoed in another php-page. Therefore I use file_get_contents() and echo the result.

$Content = file_get_contents("page.php");
//remove parts of the content I don't need 
echo $Content;

This works fine until the first mentioned code executes: it stops at the first > sign.
The remaining characters are printed as html text. In this case the output is:

";} ?>

I know that the script starts executing, because its behaviour does not occur when the condition of the if statement is false.
All my pages have the extention .php and all my scripts are marked with <?php and ?>
Why does the behaviour of the script change?

Remark: I tried to use &gt; in stead of >. This works but not everywhere.
Example: print "some text<br>some other text" displays nothing anymore when > is replaced by &gt;
And print nl2br("some text \n some other text";) neither

Jeroen G.
  • 39
  • 7
  • 1
    _"I know that the script starts executing"_ - no, it doesn't. `file_get_contents` reads the content of the file as-is, any code contained in there will _not_ get parsed. You just echoed _unparsed_ PHP code to the browser, for it to interpret as if it was actually proper HTML. But `` is not an HTML tag the browser knows, so it ignores that, and displays the content that comes after it. Which here - we have to look for the next `>` to close this tag - is `";}`. – CBroe May 19 '22 at 14:31

0 Answers0