0

Why might this not work. I have an html doc:

HTML

<head>
<h1><?php include "test.php"; echo "$intro" ?></h1>
</head>

PHP

<?php
$intro = "Welcome to PHP."
?>

Nothing shows up on my page... I just running it from my desktop right now.

  • Does it work if you try to echo something that isn't being imported? If so, I'd say it's in import problem. – Carcigenicate Feb 28 '17 at 21:24
  • Because PHP is a server side language which requires a webserver configured to work with PHP. Opening a file which uses PHP in your browser directly will not work, as there is no PHP interpreter to "execute" the PHP code. – Joe Feb 28 '17 at 21:25
  • 1
    http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-i-can-see-it-on-source-code-of-page –  Feb 28 '17 at 21:27

2 Answers2

0

A couple of things to help you:

  1. h1 tags go in the body, not the header
  2. make sure you are serving this file with the php exe
  3. no need to wrap $intro with quotes
NathanS
  • 61
  • 3
-1

well are you running it from a local server?

if you are not running on an actual in house server and your pages don't end in .php it will never work. PHP needs a server to work

ATechGuy
  • 1,208
  • 8
  • 13