0

Taking an internet programming class and our first assignment was to grab input from an html form and echo it out in a php page. After many frustrating attempts to get this to work, I just tried to make a php page that echoes out "hello world" but not even that worked. It echoed out "echo 'hello world';"

When I try to view my php files in chrome, I just get the source code to display but I want to be able to view it as if it were a webpage.

I don't know how to show my code properly on here. Anytime I try to combine < with ?, it just shows up as

Ok. I've got the hello world one working, but now I have an issue where I can't echo out variables.

Got it working! My local server wasn't on, and then for the actual assignment the syntax was wrong. Thanks for all your help and patience!

UW_Huskies_01
  • 71
  • 1
  • 10
  • 1
    Hi, please show us all the code of your `Hello World` script. And the other one if you like. As with most questions on SO you will always get a better response if you include some code we can see – RiggsFolly Aug 30 '18 at 15:47
  • 1
    Most obvious other possible issue! Did you install a web server with PHP configured within it? – RiggsFolly Aug 30 '18 at 15:48
  • Show your code please i can 100% be sure its an out of place symbol/apostrophe or something like that – connorg98 Aug 30 '18 at 15:48
  • 1
    To the Chrome browser, a .php file is just a text file. You need to have the file on a PHP server, such as Apache, for it to do anything - the server will take the php commands and turn them (eventually) into HTML that the browser can understand. OK, that's oversimplifying things, but hopefully you get the idea! – Peter HvD Aug 30 '18 at 16:06
  • Is there a tutorial video or something similar you could link me to? I have absolutely no idea what I'm doing. This is the first time I've studied web development in about four years and back then I only barely had a grasp on html and css; we didn't even get into php. – UW_Huskies_01 Aug 30 '18 at 16:16
  • does the url in the browser address bar start with `file:////` or `http://` – RiggsFolly Aug 30 '18 at 16:19
  • file:///C:/xampp/htdocs/hello_world.php is what I type in – UW_Huskies_01 Aug 30 '18 at 16:21
  • Then you did not install a web server or you are not using it if you did. You can run HTML and Javascript raw in a browser, but you need a web server configured with PHP to run PHP code. Take a look at WAMPServer or XAMPP – RiggsFolly Aug 30 '18 at 16:25
  • I have XAMPP installed – UW_Huskies_01 Aug 30 '18 at 18:27
  • Re edit: If you have a new question, then [ask a new question](https://stackoverflow.com/questions/ask). Make sure you include a [mcve]. If you are still having trouble formatting code in your question, look more closely at the formatting buttons along the top of the editor box. – Quentin Aug 30 '18 at 20:40

3 Answers3

0

Ensuring that your file is saved with the extension .php:

<?php

echo 'Hello World';

?>
Matt Jameson
  • 582
  • 3
  • 16
0

1.- "echo 'hello world';" is wrong, should be

<html> <?php echo "Hello World!"; ?> </html>

2.- You need a server, you can't only open file with the explorer, check apache or nginx.

Jarboox
  • 23
  • 1
  • 7
0

You should not load php files directly. Instead, make sure your XAMPP servers are running help on that here, and navigate your browser to http://localhost/hello_world.php

mblaner
  • 1
  • 1