My XAMPP can't read PHP code

Problems with the Windows version of XAMPP, questions, comments, and anything related.

My XAMPP can't read PHP code

Postby ranz » 26. January 2014 03:10

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!
ranz
 
Posts: 2
Joined: 26. January 2014 03:01
Operating System: Windows

Re: My XAMPP can't read PHP code

Postby Altrea » 26. January 2014 03:57

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
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: My XAMPP can't read PHP code

Postby ranz » 26. January 2014 04:25

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.
ranz
 
Posts: 2
Joined: 26. January 2014 03:01
Operating System: Windows

Re: My XAMPP can't read PHP code

Postby Altrea » 26. January 2014 11:17

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.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: My XAMPP can't read PHP code

Postby Nobbie » 26. January 2014 20:35

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.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 136 guests