Page 1 of 1

My XAMPP can't read PHP code

PostPosted: 26. January 2014 03:10
by ranz
Good day!

I got a little trouble in my xampp. I donwload it yesterday, and i want it to try so i try a simple code.

Code: Select all
<?php
   echo "Hello!";
?>


When i run it using the notepad, it output the same way i typed it. And when i type localhost/htdocs/hello.php. It gives an error 404. What should i do?

Thanks in advance!

Re: My XAMPP can't read PHP code

PostPosted: 26. January 2014 03:57
by Altrea
Hi ranz,

ranz wrote:When i run it using the notepad, it output the same way i typed it.

This will not work. You cannot test a file using notepad.

ranz wrote:And when i type localhost/htdocs/hello.php. It gives an error 404.

http://localhost/htdocs/hello.php will request the file \xampp\htdocs\htdocs\hello.php
What is the correct path of your file?

ranz wrote:What should i do?

Use the correct URL for the file you want to request

best wishes,
Altrea

Re: My XAMPP can't read PHP code

PostPosted: 26. January 2014 04:25
by ranz
ranz wrote:When i run it using the notepad, it output the same way i typed it.

This will not work. You cannot test a file using notepad.

I mean, i directly open it with my browser using the run button in the taskbar of the notepad. The html code i made is working fine with this method. But in php, the output is the same as you typed it in the notepad.

ranz wrote:And when i type localhost/htdocs/hello.php. It gives an error 404.

http://localhost/htdocs/hello.php will request the file \xampp\htdocs\htdocs\hello.php
What is the correct path of your file?

C:\xampp\htdocs\hello.php, this is the path of my file.

Re: My XAMPP can't read PHP code

PostPosted: 26. January 2014 11:17
by Altrea
ranz wrote:I mean, i directly open it with my browser using the run button in the taskbar of the notepad.

That will not work.
PHP is a serverside running programming language so every php code needs to be parsed by the php interpreter first.
Your Notepad does not know that you have running a php interpreter somewhere on your computer and where to find it.

ranz wrote:The html code i made is working fine with this method. But in php, the output is the same as you typed it in the notepad.

Your browser does not know anything about a php interpreter too. It can only process code it can understand which is HTML, CSS and JS.
Everything else will simply get outputted as plain text.

ranz wrote:C:\xampp\htdocs\hello.php, this is the path of my file.

Then the correct URL would be http://localhost/hello.php, no htdocs in the URL.

Re: My XAMPP can't read PHP code

PostPosted: 26. January 2014 20:35
by Nobbie
ranz wrote:I mean, i directly open it with my browser using the run button in the taskbar of the notepad. The html code i made is working fine with this method. But in php, the output is the same as you typed it in the notepad.


The reason is, that browser can understand HTML, but they do not understand PHP. PHP is transformed to HTML by a Webserver running a PHP Interpreter, before handed out to a browser.

You definately should go for a good book and/or tutorial, in order to understand the architecture of web browsers, web servers, PHP, HTML and and and - how it works together and it is related to each other. It is a MUST to understand how it all works together.