What is PHP?
- Php is server side scripting language.In other words php is a processing language.It process the scripts and returns the output in the form of HTML.
- Php is not used for apperance but for processing.
- Simple example of php is contact form.When we fill the inputs in contact form such as name,mail,message and subject and submit it the information is passed to the Blog/Website owner.
- Php is responsible for passing this information.It takes the input from the form processes it and sends it to respective email.
Hot to give php tag :
Php tag is given by
<?php //php code ?>
Printing a word in php :
- Printing function in php is given by echo.
- Below code prints “this is my first php code”
<?php echo "this is my first php code"; ?>
Variables in php :
- Variables in php are really simple.
- Lets check the following example:
<?php $x=5; $y=6; $z=$x+$y; echo $z; ?>
- Here x and y are variables
- As in Algebra ,variables can be used to hold values in php
- On compiling this code we will get the answer 11.As simple as in algebra.
Rules for using variables in php :
- Php statements and variables are case sensitive.
- Varibale must start with $.
- Varibale name should start with a letter,underscore or character.
- Variable should be alpha numeric i.e it can start with a-z , 0-9, _
- Variable name should not contain spaces.
- In php there is no need to define data type , php automatically identifies data type depending on its value.
Assigning variables to text value :
When we assign variables to text value,put that value in double quotes.
<?php $x=“ajinkya”; $y=5; echo “$x $y”; ?>
- The output will be ajinkya5
- If we put $x=ajinkya instead of $x=“ajinkya” the code will not be executed.
Variables scope in php :
- There are 4 type of variables in php.
- Local variables
- Global variables
- Static scope
- Parameter scope
We will study each one in detail in next tutorial variable scopes in php .If you have any question feel free to ask me.I will be glad to answer them.If you find this post useful share it with your friends.
In the following tutorials we have explained more ways to create a website, you will definitely like it.It’s simple and easy to understand very valuable series of tutorials for beginners. Checkout the links.