0

This file (test.php) runs the PHP info blurb as expected:

<html>
<body>
<?php  
   phpinfo();
?>
</body>
</html>

But this code, also when saved as test.php, generates a blank screen:

<?php
echo "<html><body><?php phpinfo(); ?></body></html>";
?>

The source code here, when reviewed from the browser, shows:

 <html><body><?php phpinfo(); ?></body></html>

...so almost certainly there is something screwy about how I've set up the server to parse things..

I am running a localhost of PHP version 5.6.28 and Apache 2.4 on Windows 10. Other than the newbie setup instructions here, I haven't changed many of the defaults. I do have:

LoadModule php5_module "c:/php/php5apache2_4.dll"
AddType application/x-httpd-php .php

...already in the httpd.conf file.

test.php definitely has a .php extension already, but I did see this idea, so I added this line:

AddHandler php-script .html

...to the httpd.conf file. I also added:

AddType  application/x-httpd-php-source  .phps
AddType text.html .php

that were suggested here: Apache is downloading php files instead of displaying them

Am I missing something obvious?

Update: after monkeying by adding the above lines to the httpd.conf file, test.php actually generates a few unescaped characters?

"; ?>

rather than a totally blank screen, or the expected phpinfo information.

Community
  • 1
  • 1
Suzanne
  • 512
  • 2
  • 9
  • 26
  • 2
    You are echoing out PHP code to output, that output will not be parsed by the PHP engine. – flauntster Dec 12 '16 at 04:05
  • So maybe `echo` isn't what I want -- how can I create code -- in a string, say -- that will be executed? For example, creating forms from code: echo '
    ';
    – Suzanne Dec 12 '16 at 04:25

2 Answers2

1

Going by the comment you posted above, you're looking to concatenate output. Using your example, you could use:

echo '<form id="option-listing-form" method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '"> ';

Hope this helps :)

flauntster
  • 1,967
  • 12
  • 19
0

You don't need the HTML markup tags

<?php
phpinfo();
?>

To fix your mistake though

echo "<html><body>";
phpinfo();
echo "</body></html>";

phpinfo() returns bool (that is; true or false), it outputs on the fly, no need to echo it out.

PS Your parser is fine if it echo'd anything out, you're just lacking a greater understanding of the syntax

zanderwar
  • 2,483
  • 1
  • 19
  • 42
  • Right -- but where I'm going with this is, I'm trying to find a way to generate PHP code that will be parsed, not just printed. I have more complicated statements like `echo '
    ';` that are being printed rather than parsed.
    – Suzanne Dec 12 '16 at 04:22