PHP file should be SERVED by web server (Apache) with PHP enabled (mod_php)
If it runs on YOUR computer you should be accessing it as http://localhost/yourPHP.php
the php is not interpreted or read by the browsers! it needs to be interpreted, and this interpretation is done *before* sending the data to a browser.
this means that you can’t open a local “php” source directly with the browser and pretend it executes the code!
you must install/activate a web server (with php interprer) on you machine, and you must access the file through the local web server, as if it were online (e.g. you write http://localhost/mysite/myphp.php )
doing so, the web server “listen” to the request of the “myphp.php” file from the browser, before sending it, the server will pass it to the php interpreter, and the result of such processing will be sent, through the web server, to the browser.
a web server e.g. is apache (it exists also IIS by microsoft)
PHP runs at the server level. You need to install a local PHP package on your machine in order to become a server for this code to work, otherwise only the HTML is being interpreted, which is why the ONE is seen. The browser simply interprets the < ?php echo "two"> brackets as simply another tag, which it ignores as it does not know what to do with it. Once you install a local PHP package, it will work as advertised just as it does at the server level from a remote server returning the page.
6 Comments