Ads

Tuesday, November 15, 2016

PHP - Use of Variables

Today, we will learn the use of variables in php scripting.Variables are also called memory locations where we store the input/processed data.In php, We use a $ (dollar) sign for variables and we can use it anywhere in the script while execution.To set a value of a variable, we use = (equal) sign.The value of variables in any program cannot remain constant.It means that the value of variable can be changed in the program while executing it.Here is sample php script where we'll use variables to print data on the screen.












Simple PHP Script with Variables:

<?php

  $Var1 = "My First program...";

echo $Var1;

?>
Output:

My First program...

Please note that all the strings must be written between double quotations " " otherwise you will get error message while executing the script.To write a number or mathematical operations, we can use them without double quotations.Here is an other php script where we'll define a variable and set its value as a number

 Numbers in Variable:


<?php

  $Var1 = 100;

echo $Var1;

?>
Output:

100
Here is another example of getting sum of numbers by defining a variable

<?php

  $Sum = 786 + 234;

echo $Sum;

?>

Output:

1020

In next article, we'll learn the use of Constants in PHP

Monday, November 14, 2016

PHP - First Hello World Script

In the previous post, we have been created an environment for php.Now we can develop and test our php scripts on our Personal Computer so, Lets start with a Hello World PHP Script. 
Now, I'll tell you about php syntax.To start your php script, we always use these starting and ending tags so, the server will execute the file as PHP Script.
<?php


  ?>
These two tags are required to execute your code in your web server otherwise it will display as text plain in the browser.
Now, lets create a new Hello World script.

Please follow these steps::
Step 1: Open PHP Designer 8 and create a new PHP File
when you will click on new php file, php designer will automatically add php tags into the file so, you need not worry about php tags.
Step 2: Write this code into the file
<?php echo"Hello World"; ?>
Here echo is a php syntax which is used to display a message on the screen.In php programming, every line must be separated by a semi-colon otherwise it may cause errors while executing the script.
Step 3: Save the file into the Document Root (Default: C:\xampp\htdocs\) and write the name helloworld.php
Now, its time to test your php code in the browser.Lets check it
Open your Browser and navigate to http://localhost/helloworld.php 
when the page will be loaded, you see the output like this:
 Congratulations! You have successfully developed your first php script!

PHP - Get Started

Today, we shall get started with PHP and shall create a localhost web server for testing purpose.A localhost web server works like a live website.Today, We'll learn about a software which enables us to create a localhost on our computer.To work with PHP, we'll have a localhost to test the PHP Scripts so, Lets start






How to Create a localhost on Windows PC?
Here is a software which allows you to make your own local website which works like a live site.It contains on PHP,MySQL and Apache.It means that you can test your web apps on your local pc without uploading them on your live site.The name of that software is XAMPP for Windows.
What is Xampp?
Xampp is a Windows Software which converts your PC into a local website with Apache and PHP.User can develop and test his web apps (Written in PHP or Perl) on his own pc without having a live site.You can download Xampp from its official site.







Download Xampp for Windows

How to Install Xampp?
After downloading the Xampp for Windows, just double click the setup and select the Features you want to install and click next.After successful installation, open the xampp control panel from your Desktop or Start Menu and Start the Apache Service.When you see the green bar with running text beside the Apache Service, click on Exit and open your web browser, there write http://localhost/ in the address bar and click GO.You'll see your Xampp Welcome page.
Your document root will be like this: C:\xampp\htdocs
all your PHP files will stored in that folder so that, we can access them from browser.

Now Everything is done and Now we need a Programming IDE (PHP Editor) so that, it will be very easy to develop your php scripts.

Here, we'll use PHP Designer 8 as IDE which can be downloaded from the link bellow.
Simply download the app and install it.
Download PHP Designer

php, php programming,php developer,xampp,php designer,web development,php scriptinh