user3511259
user3511259

Reputation: 97

PHP inside HTML doesn't work

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

Here's the code:

<html>
<head>
</head>
<body>
            <?php
            echo "hdfguhbgzusgdfghdhhfgh";       
            ?>
</body>
</html>

Upvotes: 6

Views: 62440

Answers (6)

David Liebherr
David Liebherr

Reputation: 1

Phew, 9 years ago! But, I just wanted to add that you can do a short hand syntax like this: <?= 'Some text' ?>

while the long hand would be: <?php echo 'Some text' ?>

PHP is great and will be around for a long time!

Upvotes: -1

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.

Upvotes: 4

Gizzmo
Gizzmo

Reputation: 719

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.

Upvotes: 16

juniorb2s
juniorb2s

Reputation: 242

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.

Upvotes: 0

Jan Matoušek
Jan Matoušek

Reputation: 1

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

Upvotes: 0

ponciste
ponciste

Reputation: 2229

you missed php after <?

so, change:

<? echo "hdfguhbgzusgdfghdhhfgh";  ?>

with

<?php echo "hdfguhbgzusgdfghdhhfgh";  ?>

Upvotes: 0

Related Questions