Welcome to the first tutorial in the PHP section of ReadnTeach.com. PHP stands for "PHP: Hypertext Preprocessor" which basically means all the PHP code is ran before the page is displayed. This means if you view the source of the page you wont see any PHP code.
PHP is used to create dynamic content - often powered by a MySQL database and the files most commonly have the extension ".php". To work with PHP you will need a Web server, the files will not work locally like HTML. There are a variety of free hosting plans out there - you can find a comprehensive list of free Web hosts here.
When using a Web server all files you want to display must go in the public_html folder. You can find a complete guide on how to upload a Website to a Web server here.
So onto the actual code. Firstly HTML and PHP can be included simultaneously in the same file, you simply surround your php code with php tags like below:
Code :Normal HTML can go here
Output:Normal HTML can go here
As you can see you use to surround your php code and HTML code can still go in the same page. To output some text onto the screen with PHP you use the following code:
Code :
Output:This is some text!
From the above code you learn two things. One that to output text onto a page you use the echo statement and secondly that all PHP lines must end with a semicolon. Finally for this tutorial you will learn how to comment in php:
Code :
You may be wondering why comment your code. Well if you work in a development environment working with other programmers adding in comments will help them to understand your code. Also if you leave a project for a while and come back to it you will be able to understand it quickly.
Well that concludes this first tutorial on PHP. In the next tutorial we will look at variables and operators.
|
|
||
To post comments you must sign in to your account below!
If you do not currently have an account click here to create one now!