Tuesday, May 7, 2013

PHP Tutorials for beginners – Variables

php variableHi Friends, Hope you are doing well. I believe that you have gone through our previous PHP tutorials and get some ideas. That is fine. Today we are going to talk about PHP Variables.

PHP variables as containers for storing data.

Rules for PHP variables:

  • A variable starts with the $ sign, followed by the name of the variable.

  • A variable name must begin with a letter or the underscore character.

  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).

  • A variable name should not contain spaces.

  • Variable names are case sensitive ($y and $Y are two different variables).


OK. Do not get sleepy, If you go for example you can easily understand what is variable.

For eg 1:
<?php
$a = "Hello, ";
echo $a;
?>

Check this output in your localhost, it will show Hello. 

This is it, Here $a is a variable, which contains hello value into that. Like that way we have to use php variables.

Eg 2:
<?php
       $v = 2500;
       $x = 7500;
       $y = 5000;
       $z = $v+$x+$y;
       echo $z;
?>

Do this practice in your localhost. Now you can get clear view about these variables.

Notes:

We do not initiate data type in PHP variables. It automatically converts the variable to the correct data type, depending on its value.

If you use alphabets, make double codes (in between that). for example ( $name = "hello word, how are you"; ) and should end with semi colon.

PHP has four different variable scopes. We will see about those in next tuto's.

Thanks for reading. Post your comments.

Wednesday, May 1, 2013

PHP Tutorials for beginners – 2

Hi Guys, Hope you guys have successfully installed xampp server or wamp server in your computer. That's is fine, Still If you have confusion go back to our previous tutorial or put your queries

in comments section, I will try to update you. As I told you earlier PHP is a server-side scripting language designed for web development. It is influenced by C, C++, Perl and Java. For this PHP implementation you must know basic programming about C language coding. If you are good in C or Java, Which is very easy to implement. PHP commands can be embedded directly into an HTML source document rather than calling an external file to process data. You can make a full php code to output. Like that way we are going to develop.

PHP codes must start with <? and ends with ?>. In between these we should put our code.

OK let us start our first php program here. Open any editor like notepad, notepad++, intype etc. which is your favorite in your system, do write following eg codes.

Eg 1:

Assume we should display Hi everyone, This is a beautiful world with beautiful people. we are going to display this sentence through PHP.