Brief History of PHP:

HTML :

It was developed in the year 1991 by Berners-Lee. HTML stands for Hypertext Markup Language. It is created to well-formatted web documents. HTML is a structural language for web pages. It is a language for formatting web-pages. It has limited design capabilities. We can’t make appealing and well-designed websites by using HTML. Hence, we use CSS for well design.

CSS:

CSS stands for Cascading Style Sheet. It was developed by Hakon Wium Lie in 1994. It is used to create appealing and well designed. It is a presentational language for web pages and also it is reformatting web pages.

JavaScript:

JavaScript was developed by Brendan Each in the year 1996. It is used to add behavior and interactivity to web elements or to create interactive web pages. It is Client Side scripting language. JavaScript is a behavioral language for web pages.

We can’t use be able to create real-time dynamic websites using only HTML, CSS and JavaScript. Hence, we use PHP language.

PHP :

In 1996, Rasmus Lerdorf has developed PHP language at Zend Technologies. It is used to create real-time dynamic websites.

Initially, Rasmus Lerdorf wrote PHP to maintain his Personal Home Page later extended in database, files system and web forms, It is called as PHP/FI (Personal Home Page/File Interpreter). After that name changes in PHP stand for Hypertext Preprocessor.

Before Learning what you know

  • HTML/CSS
  • JavaScript
  • Difference between PHP and HTML
    PHP HTML
    Language Scripting Language Markup Language
    Side Server-Side Scripting Client-Side Scripting
    File Extension .php .html
    Code Execution In Web Server On Web Browser
    Create Web Pages Dynamic Static
    Can Manipulate Data Yes No

     

    Difference between PHP and JavaScript

    PHP JavaScript
    Type of Scripting Lang Server-Side Client Side
    Programming Paradigm Prototype Based Class-Based
    Platform Independent Yes Yes
    Case Sensitive Yes Yes
    Access to Database No Yes
    Access to File System No Yes
    Can be embedded in HTML Yes Yes
    Security Less Secure

What is PHP?

PHP Stands for PHP – Hypertext Preprocessor. It is server-side scripting language and it is embedded with HTML, Mainly it is used for Web Development. PHP is used to generate dynamic pages content, wide range database handle, user access etc. It is executed on the server. PHP is free to download.

How PHP works?

Above image show how PHP works. I have already told that PHP is the server-side scripting language. Client hosts their website on Web-Server and he can access the website from this server. PHP is just like Interpreter. By using PHP interpreter to access the Files, Database, and Mails. First, it takes all data and interprets on this data. After that, it sends all requested data to the web server. And at last web server, it gives to a Client user. Server site interpreter can be used to access files, database and, mail easily. This is a simple example of PHP work.

What is PHP File do?

  • PHP files can storing text, HTML code, Javascript Code and PHP code.
  • The file extension of PHP is ‘.PHP’
  • The PHP code executes on server and result return to the browser as plain HTML.

Uses of PHP?

  • It can create new dynamic pages.
  • PHP can collect form data.
  • It can Send and Receive cookies.
  • It can create, open, read, write, and Close file on the server.
  • It can also add, delete and modify data in your own database.
  • PHP can do encrypted data.
  • By using PHP, restrict user can access some pages on your website.

Why we use PHP?

  • PHP can run on different platforms like Windows, Linux, Unix and Mac OS etc.
  • It can be supported and easily handle a wide range of database.
  • PHP is free to download.
  • Easy to learn and run efficiently on server side.

Which are the Characteristics of PHP

  • Simplicity
  • Efficiency
  • Security
  • Flexibility
  • Familiarity

Basic PHP Syntax:

A PHP script can be put anywhere in the document. The script starts with <? And end with ?>.

Syntax- <?

                 // PHP code here

                ?>

By default file extension of PHP file is ‘.php’.  It files normally contains HTML tags and some PHP scripting code. Below, we show an example of a simple PHP file, with a PHP script that sends the text “Hello PHP World..”

Example :

My first PHP Example

<?

echo”Hello PHP World..”;

?>

In PHP program, each code line must end with the semicolon ‘;’. The semicolon is a separator and it is used to distinguish between a set of instructions. ‘echo’ and ‘print’ both statements are used to show the output on the browser.

Comment in PHP:

A comment is used to the partition of the program that exists only for the human reader. It will help to coders in the future to understand what you write in your PHP code. There are two type of comment

1- Single Line Comment:

In PHP Single-line comment starts with ‘//’.

For example :

2-Multi line Comment:

In PHP Multiline comment starts with /*, and ends with */.

For example:

Variable in PHP:

PHP variables can be used to hold values (x=5) or expressions (z=x+y). The variable can have short names (a and b) and descriptive names (rollno,marks,class).

The most important things to know about variables in PHP.

  • In PHP all variables are denoted with the dollar sign ($).
  • The value of a variable is the value of its most recent assignment.
  • Variables are assigned with the equal to ‘=’ operator, with the variable on the left-hand side and the expression to be evaluated on the right.
  • Variable cannot start with numbers.
  • Variables used before they are assigned have default values.
  • A variable does not know in advance whether it will be used to store a number or a string of characters.
  • Variables name are case sensitive like $name or $NAME.
  • PHP is converting one type into another automatically when it necessary.
  • In PHP, variables must start with the only letter and underscore character.
  • PHP variables are Perl-like.

How to declare the variable in PHP?

A variable is just like storage area. We can store the values as number, text etc. In PHP, declaring variables using ‘$’ dollar sign. Let see the example: $txt=”PHP Variable”;

      $a=100;

In above example, after the execution above statement, the variable txt will hold the values PHP Variable and the variable a will hold the values 100.

Check out the List of Variables Type:

  • Integers: are numbers,without decimal point ex- 10,100,1000
  • Doubles: Values means floating points number. Ex- 50.5, 555.55
  • Booleans: The Values either true or false.
  • NULL: It is special type
  • Strings: This is sequence of characters
  • Objects: It is instance of class.
  • Arrays: Indexed collections of values.

String Variable in PHP

String Variables are used to stored characters and numbers. We can manipulate string variable and it can used be in functions and store the values.  

In below example, We store the value in string variable txt. After we see this value in output of program.

<?

$txt=”PHP World!!”;

echo $txt;

?>

O/P : PHP World!!

Some common functions and operators manipulate in String.

1- The Concatenation Operator

There is only one string OPerator in PHP. It is used to join two String values. It Operator is Dot (.)

Example of Concatenation operator:

<?

$txt1=”Wel-Come To ”;

$txt2=”PHP World!!”;

echo $txt1.” ”.$txt2;

?>

O/P : Wel-Come To PHP World!!

2- strlen() function

It is used to determine the length of string value. The strlen () function returns the length of string in character.

For Example:

<?

echo strlen (”PHP World!!”);

?>

O/P: 11.

3- strpos() function

It is used to show the string and specific character within string. In this function, if character is match, it will return the character position of first match and If no match found, It will returns false and exit.

In below example, search for the text “world” in the string “PHP world”.

For Example:

<?

echo strpos(”PHP World!!”);

?>

O/P: 5.

PHP Constant () function

It is a name or an identifier for a simple value. Its value cannot change during the execution. By default constant is case-sensitive. The constant identifiers are always uppercase. A constant names are starts with letters or underscore, numbers, followed by any number of letters, or underscores. If you have defined a constant, it can’t be changed. Only boolean, integers, float and string can be contained in constants.

For Example:

<?

define(“SIZE”,10)

echo SIZE;

echo constant(“SIZE”);

?>

Get and Put method in PHP

1- GET Method in PHP

Get method sends  the encoded user information appended to page request. The encoded information and pages are separated by ? operator.

Some following points of GET():

  • The Get method is restricted to send upto 1024 characters.
  • It can’t be used to send binary data.
  • Never use GET method if you have password or other sensitive information to be sent to the server.
  • In PHP, $_GET to access all the sent information using the GET method.

2- POST Method in PHP

The POST method transfer information via HTTP. The information send from with POST method is invisible to others and has no limits on the amount of information to send.

Some following points of POST():

  • It does not have any restriction on data size to be sent.
  • The POST method can also used to send ASCII as well as binary data.
  • In PHP, $_POST associative array to access all the sent information using GET method.
  • In this method by using Secure HTTP you can make sure that your information is secure.

So here we have shown the basic knowledge about PHP. This article is very important to PHP for beginners. Here we provide all the basic concepts that are easily understood by beginners.