-4

when i type my php code in a html file, using notepad++ as my text editor,why does it always show some of the code as text on the web page

eg.

<?php   echo "hello world";   ?>

would output:

"hello world";?>

as text on the web page

why does it do this and how can I stop it?

  • Probably you have a double closure in the file: you repeat;?> – Lelio Faieta Oct 28 '17 at 16:15
  • `in a html file` makes it HTML, not PHP. Unless you modified the handler, did you do that? – chris85 Oct 28 '17 at 16:21
  • @chris85 why doesn't it though as html files allow you to enter php code so why not run it – Joshua Charles Pickwell Oct 28 '17 at 16:54
  • Because PHP is run through the PHP process. The PHP process only looks for `.php` files being run by apache or any other extension it is told to look at. The same with CLI when you use `php file.php` the first `php` invokes the PHP processor. – chris85 Oct 28 '17 at 17:01

1 Answers1

0

You need to save your PHP code in a file with .php extension. To execute PHP code, you can call the interpreter from your command line with php myfile.php or from a webserver like Apache or nginx. Your browser cannot execute PHP code.

Read more about installing PHP here:
http://php.net/manual/en/install.php

If you're new to PHP, I would recommend you to read a good book (unfortunately I can't recommend one). Or if you're more the visual learner, take a look at The PHP Practioner made by Jeffrey Way.

tinyoverflow
  • 1,933
  • 3
  • 13
  • 29