Introduction Of PHP PHP is a recursive acronym for "PHP: Hypertext Preprocessor“ or “Personal Home Page”. PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites. It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle , blockchain , and Microsoft SQL Server.
Common use Of PHP PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them. PHP can handle forms, i.e. gather data from files, save data to a file, through email you can send data, return data to the user. You add, delete, modify elements within your database through PHP. Using PHP, you can restrict users to access some pages of your website. It can encrypt data.
Feature And Advantages of PHP Simple Interpreted Faster Open Source Platform Independent Efficiency Flexibility
What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect form data PHP can send and receive cookies PHP can add, delete, modify data in your database PHP can be used to control user-access PHP can encrypt data
Why PHP? PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) PHP is compatible with almost all servers used today (Apache) PHP supports a wide range of databases PHP is free PHP is easy to learn and runs efficiently on the server side
PHP Syntax A PHP Script is always executed at server side ,and browser gets the plain HTML result in response. The Location of PHP Script can be anywhere in document in the document. The PHP Parsing engine requires a method to distinguish PHP code from other script in the page . This is called escaping to PHP. The PHP Script start with <? php and ends with ?>
Syntax <? php PHP Statement; ?>
Extension Of PHP . Php is the extension for PHP Files. A PHP is Combination of PHP script with HTML Tags.
Simple Program to display Hello Message in PHP <?php echo "<h2>PHP is Fun!</h2>"; echo "Hello world!< br >"; echo "I'm about to learn PHP!< br >"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?> The echo statement can be used with or without parentheses: echo or echo().
PHP Comments <? php // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */ // You can also use comments to leave out parts of a code line $x = 5 /* + 15 */ + 5; echo $x; ?>
Variables in PHP Definition: A Variable is the Name Given to memory Location where we can store some Value . The Value depends upon the data type of the variable . Declaration: In PHP we declare Variables by using “$ “ symbol without assigning the data type. The Data type of variable is decided by the PHP parsing engine when value is assigned to it.
Addition Of two Numbers <?php $no1=12; $no2=19; $sum=$no1+$no2; echo"Summation is:-".$sum ; ?>
Conditions and Loops Control Structure If If else W hile Do While Else If ladder Switch case For For each
Function The Concept Of Programing is Same of any other Programming Language. Definition: A function is a block of statements related to such a task which we want to execute repeatedly in our program. A function can take arguments and also can return value. Up till now we have seen the function echo(). This is built in function of php. Now We will create our own user defined function. Related to functions there are two important points: 1Creating a PHP Function. 2. Calling a PHP Function
Function Syntax function function_name ( parameters) { Statements; }
Sample Program of function <?php function printmsg () { echo "hello welcome"; } printmsg (); ?>
Passing Arguments Through Function <?php function summation($n1,$n2) { $n3=$n1+$n2; echo "Summation is:-".$n3; } summation(10,20 ); ?>
Passing Argument by Reference <?php function summation(&$num) { $num += 5; } $num=10; echo "$num<br>"; summation($num); echo "$ num“; ?>
Form Handling When you login into a website or into your mail box, you are interacting with a form. Forms are used to get input from the user and submit it to the web server for processing. A form is an HTML tag that contains graphical user interface items such as input box, check boxes radio buttons etc. The diagram below illustrates the form handling process.