PHP Tutorial - Part 1

PHP First Program

Today we start the first program in PHP before starting we should know some points.

  1. After installing xampp, we save all our codes file (myfirstpage.php file) in the “C:\xampp\htdocs” folder.

    So now Start the xampp server and Start Apache and MySQL, then start notepad++ and select language from the menu bar and select PHP.

    In the XAMPP I captured the screenshot after clicking Start.

    xampp

    language

    The first program.

    start

  2. To execute the code we access our computer as a web server and domain name is localhost or access by local IP 127.0.0.1.

  3. The htdocs is the root folder of our local web server. To execute the file we enter the following URL in our browser: localhost/myfirstpage.php.

    run

  4. Then the program will execute.

Do you have a a question what is echo? Yes!

The echo is the function that prints the data on the screen. The print() is the old version of echo and it is not used so much used in the coding.

PHP variables

Understanding variables is very simple in php . There are some rules about PHP variables.

  1. First character must start with dollar sign ($).

    Example: $count = 0;

  2. At least one character should be in the variable except $.

  3. We can use underscore in the variable name.

    Example: $Adhaar_number ;

  4. Spaces and special character other than (_) and ($) are not allowed.

    Some rules that are least important but good for coding skills.

  5. Always the variables name are in lowercase.

  6. To separate multiword use (_) sign.

Now the time is to see an example of Variable.

example of Variable

You can print the variables using the echo function.

So there are many things you can understand by only seeing this example. I am now explaining one by one:

  1. The is no data type written before variable language unlike other programming languages like C, C++, Java, etc.

  2. We only simply write dollar then variable name.

  3. If we give the value to a variable a int then the php act it as an int. Same in float, long, etc numerical variables.

  4. But when the value is in the inverted commas, php act it as a String. For example, $value=’100’,name =”RAdha”, $value =”100.876”, &value=’20.876’ these act as a string.

  5. If we talk about the Boolean, I thinl you know about that.


Similar Articles