I keep reading comments that PHP code has to be compiled. I have been pasting exampled PHP code into a web page, is that why it does not work. I am publishing it on a hosted site before running it, having PHP, MySql etc on the server. Regards
PHP is, generally speaking, an interpreted language. There are compilers that can compile PHP scripts to something similar to Java p-code, but in most applications, PHP scripts are interpreted.
One simple PHP script that does useful things is:
Code:
<?php
phpinfo();
?>
What happens when you put the above into a script file on your server and point to it with your web browser?
PHP does not need to be compiled, it is interpreted by the server upon request. The thing to check for is the extension of the webpage. if it ends in htm or html, it will not work unless the server is configured to parse files with html extensions. Most servers with php only parse files with the php extension, like mypage.php.
Many thanks sleipnir, I pasted the code into a page, published it, and looked at the site on the browser and it was a blank page. Thanks also vacunita, the page name is Test.htm? the code placed in the page is:
Aha, I changed the page name to end as .php and the phpinfo came into life. So you were correct, the servers looking for pages identified as PHP. Does that mean I cannot put any HTML code in there?, I will try. However both you folks deserve stars, as I have spent so much time trying to see something appear. Have a good weekend both, thanks again.
You can still put html code in there. Only items between <?php> tags will be parsed by php, the rest will just be forwarded on to the browser as if a regular file.
The only difference is that a file must in with .php to be parsed. This leads to a more efficient server (not every file needs to be passed through the php interpreter before being served) but it also makes it obvious to the user that you are using php to generate a dynamic page.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.