NO hello world ?!


#1

Hi,
am total novice with PHP
MUST be doing something wrong
Have narrowed down to the classic

<?php echo "Hello World" ?>

saved as file ech.php
but when I try opening file in Firefox 61.0.1 I see nothing
In the F12 bar I get :-
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

In that this is purely php what is happening and how do I get it working properly.

Thanks Bob


#2

Php is a server-side scripting language. You don’t open the .php file in your browser, you make a http(s) request to the web server where the .php file is hosted at in order to cause the php code in it to be parsed, tokenized, and then executed.

To do this on your local computer, you need to install at least a web server and php. You can use one of the all-in-one packages, such as xampp - https://en.wikipedia.org/wiki/XAMPP

The .php file would be saved in the web server’s htdocs folder and the url you would use in your browser would be - http://localhost/your_file.php


#3

Hi,
thanks for reply.
Sorry I should have said that I was using XAMPP and the file is under htdocs etc.

file:///D:/xampp/htdocs/RF_htdocs/WEBS…blah …/ech.php

You can see the source under Firefox --> Web Developer --> Page Source so it is looking at the right file.
Bob


#4

Your still not calling it through the server if that is the URL. The URL should be localhost/filename.php

Looks like you have an odd path to the app/script as well. What is with the deep nesting of folders?


#5

I use Wampp, not Xampp, but they are similar. When running and online, you get a control panel in the tray by your clock. You can select it and then go the local-host and see your sites you have set up on it. Remember that you must place your website you are testing inside the local-host folder. So, if on the C: and using Xampp, it might be something like C:\xampp\www\your-folder\your-index-file…

this means that you have to know the structure of your local Xampp system and where it houses your websites. Then, you can move your testing folder of your website there and call it using the local-host system.

Not sure if that helps, but, look into it and ask further questions on this!


#6

Thanks for replies - greatly appreciated

Many thanks benanamen now see the error of my ways.
Not sure how I got fixated on that pattern for URL

All ok now
:grinning: Bob