4

I just want to know why does this HTML file shows nothing:

  • I'm running it on a web server
  • Name of the file is index.php
  • I've fixed the <? issue but it still doesn't work

Here's the code:

<html>
<head>
</head>
<body>
            <?php
            echo "hdfguhbgzusgdfghdhhfgh";       
            ?>
</body>
</html>
halfer
  • 19,471
  • 17
  • 87
  • 173
user3511259
  • 77
  • 1
  • 1
  • 6
  • 1
    It can be because apache2 don't know this is a php file. Usually, you only have to set the extension of your file as ".php" You should use – vekah Apr 08 '14 at 13:58
  • 4
    Are you running a web server? If you're just opening an HTML file in the browser, this won't work. – Nicholas Flees Apr 08 '14 at 13:58
  • 4
    since it has php part, the file should be saved with .php extension, and the server should support php, also, please use ` – dlyaza Apr 08 '14 at 13:58
  • You gave us not enough info to help you. Do you have webserver running? Do you have short_open_tag enabled in php.ini? What about extension and settings for it? – scx Apr 08 '14 at 14:01
  • @nickflees if he wasn't running a server he would see php code. I would guess short tags are disabled. – Mattt Apr 08 '14 at 14:02
  • what is your file extension? – DS9 Apr 08 '14 at 14:03
  • @DS9 Can't be an extension issue. If he served this as a .html page it wouldn't be blank. You would see the PHP in the browser if it wasn't parsed. – Mattt Apr 08 '14 at 14:05
  • Check your Apache logs to see if there's any errors in there. – halfer Apr 08 '14 at 14:21
  • I had the same problem: my mistake was the HTML extension. Changing to PHP solved the problem. – Angelo Mascaro Aug 06 '19 at 16:29

5 Answers5

13

You should make sure that following are given:

  • PHP on your server

  • Files have to end with ".php"

  • Use open Tag <?php and not <?

Then it should work.

For a definite solution you should provide further information.

GypsyCosmonaut
  • 509
  • 10
  • 16
Gizzmo
  • 681
  • 7
  • 21
4

As edited by halfer on Apr 8 '14 at 14:13, the showing code had no <? problem anymore. The code seemed well written.

In case those code still do not work, perhaps people must add:

AddHandler application/x-httpd-php .html

inside the .htaccess file.

The .htaccess file must be in the same directory with your html file. If you can't found the .htaccess file although you already turning on the show hidden file option, you can create new .htaccess file and include AddHandler mentioned above in the file.

Just create a blank text file and name it with .htaccess on the mentioned directory.

0

you missed php after <?

so, change:

<? echo "hdfguhbgzusgdfghdhhfgh";  ?>

with

<?php echo "hdfguhbgzusgdfghdhhfgh";  ?>
ponciste
  • 2,226
  • 12
  • 16
0

Some tips:

  • If you dont see the text, try to open source code in browser.
  • Make sure, that your file is .php and not .html
  • Use <?php as opening tag instead <?
  • If you want to just echo text, you can use <?echo "YourText"; ?>

Everything else seems OK

0

The short_tags comes disabled by default, so you have to use

<?php
  echo 'Teste';   
?>

invés de:

<?
  echo 'Teste';   
?>

To enable the option to just turn short_tag in php.ini http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

PS: For performance reasons it is recommend to use "(double quotes) only when the echo is variable, so that PHP will parse and find the variable If you place." (Double quotes) there is no variable in the php echo to atoa parsing, try waste of charge.

syck
  • 2,947
  • 1
  • 11
  • 20
juniorb2s
  • 234
  • 4
  • 11