Notes of PHP Part 1

PHP Definition

PHP is abbreviated form Personal Home Page. PHP stand for Hypertext Preprocessor. PHP is basically a server-side scripting language which is designed for web development but also used as a general-purpose programming language.

How we Write PHP Script

PHP script writing is very simple. we don't need any special software for writing PHP. we can write PHP script in any text editor like Notepad in Windows or excellent and free Notepad++. after writing save it with .php extension.
Structure of PHP Script
PHP scripts are always enclosed in between two PHP tags which is <php? and ?>. These two tag tells to server to parse the information between them as PHP. There are three three different forms which are follows:
1. < ? Your PHP Code Is Here ?> 2. 3.

Note:- Every statement in PHP end with semicolon ( ; )
Running and Testing Your Script in Browser
When we save the php file we must store this file inside the web folder of a web server and then make a request to desired PHP file by typing its URL in the web browser. After installing web server software in computer, usually the root of its web folder can be accessed by typing http://localhost in the web browser. if we save the file test.php in web folder the we write http://localhost/test.php in browser address bar. If we install XAMPP to install Apache (web server) in your computer then the web folder would be htdocs which is under the root directory of XAMPP.
Printing Text in PHP
IN PHP we user print or echo command for printing the text on screen.The print statement is used in the following way:

< ?php print("Hello Learninghints!"); ?> we can also use echo command < ?php echo "Hello Learninghints!" ; ?>


print is the command and tells the script what to do. This is followed by the information to be printed, which is contained in the brackets. Because you are outputting text, the text is also enclosed inside quotation marks. Finally, as with nearly every line in a PHP script, it must end in a semicolon.
The result will look like:
1
Hello world!
Variables
Variable are those memory location where we want to store our values. In programming language a variable is just a storage area. we can put values into storage areas (variables) so that we can use and manipulate them in your program when we need.
for example
price
so in our program hold the value like that
price=20
In PHP two things have import ants in declearing variable. First, variables need a dollar sign at the beginning. as shown below:
$price = 10

Second thing which is - a semi-colon. Lines of code in PHP need a semi-colon at the end:
$price = 10;

We can also put text into variables. Suppose if want to want to store name of anything . we can put direct text into your variables:
$name = " LearningHints ";
Variable name starts with a dollar sign ($). The equals sign follows the variable name. After the equals sign, however, we have direct text . W can also use single quotes instead of double quotes. So you can do this:
$name ='Tauqeer';
But you can't do this:
$name ='Tauqeer';
Now let's take asimple example which display the value of varaible:

PHP Concatenation

We can join the text together , and whatever is in our variable. The full stop (period or dot, to some) is used for this. Suppose if we want to display the following "My variable contains the value of 100". In PHP, we can do as follow:

So now we have two variables. The new variable holds our text. When we're printing the contents of both variables, a full stop is used to separate the two.
You can also do this sort of thing:

This time, the direct text is not inside a variable, but just included in the Print statement. Again a full stop is used to separate the direct text from the variable name. What you've just done is called concatenation.