PHP Basics #3 : How to get Started with PHP coding ?

How to get started with PHP Development ?


(Continue only if you Successfully Installed Apache, PHP and MySQL)

So now you know how to run a php file in browser and its time to get started in php development !!

Today we will talk about :


  • How to write PHP codes
  • Basic Syntax
  • Echo Statement


1) How to write PHP codes ?


PHP codes can be written in any php file which means a file with .php extension and you can write it using any text editor but you must know that to write php codes you have to tell the browser that these are php codes not html and to do that all you have to do is open the php tag like all other html tags and then when php codes finishes close the php tag .. The opening php tag is and the closing php tag is ?> . The browser will take all the codes between the as PHP codes. And after you complete each php like you have to end with a semi-colon ; . A semi-colon tell the browser that the command ended. 



All codes here are PHP codes

?>  


2) Basic Syntax of PHP


PHP has very easy syntax rules as compared to other programming or scripting languages, the most important rule is to end your every statement with a semi-colon. We will demonstrate it soon and you will get hang of it.
One more important thing in php to remember is that white spaces had no effect in php coding there is no indentation rules in php, which for me is quite good.

3) echo 


If you have any experience with any programming languages then I guess you know what this statement does and for those who dont know this statement simply prints out anything you want on the screen. So if you have gone through the Last Tutorial of this series you must have created a folder in you localhost path named test and now time to use this folder for demonstration of all the exercises.
The syntax of echo statement is   
To print text in browser -> echo "Quotes if Text";
To print numbers in browser -> echo 1;
So create a new file named echo.php and inside the folder test and type the following inside the echo.php file..




echo "Hello World!!";


?>


If you open the file in browser the result will be..
Hello World!!


You can also do other things such as maths calculations..



echo 2+2;

?>

Result :
4

This was some basics of php codes and in next tutorials we will learn about PHP Variables and all..Till then do some experiments with your codes and try some more examples .. If you get stuck anywhere please comment