التخطي إلى المحتوى الرئيسي

المشاركات

عرض الرسائل ذات التصنيف PHP

PHP Introduction, What is PHP?, Scope of PHP

PHP means a Personal Home Page, It is a server-side script-based language that is specially designed to create a dynamic web application. but now PHP is professionally known as Hypertext preprocessor. Hypertext:-  PHP provide text within tag with a complete block that is Hypertext block . <?php ?> here <?   ?> is called Hypetext block Preprocessor:-  All in-built or predefined functionality will be integrated by default under PHP Hypertext block, no need to import header files and library separately. The server-side script will be executed by Web Server and communicate with the Database server for dynamic application development. For example, PHP is a Server-side script which will be executed by Apache Server and communicate with MYSQL Database , Oracle Database , MS-SQL , MongoDB, PostgreSQL , etc PHP is open-source and free source web technology that provides multiple Web Framework( Codeigniter, Laravel, YI, CakePHP, etc ) and CMS ( Content Manageme...

Create First Program of PHP,How to create first program using PHP

1) Download PHP Software Tools:-     1.1) XAMPP Serve r:-   It provides Apache Web Server, MYSQL Database Server, PHP Script, and Pearl Script. It is common for all operating systems (Windows, Linux, MAC, Solaris, Unix, Android)    X----> ANY    A ---->  Apache    M ----> MYSQL    P-----> Pearl    P------> PHP 1.2) WAMP, LAMP, MAMP is the other software tools of PHP      WAMP is specially for  Windows (W--Windows,A--> Apache,M--> MYSQL,P-->PHP)      LAMP  is specially for LINUX   (L--> LINUX,A---> Apache,M--> MYSQL,P-->PHP)      MAMP is specially for MAC      (M-->MAC,A--> Apache,M-->MYSQL,P---> PHP) download xampp from this link https://www.apachefriends.org/download.html 2)  Open XAMPP Control Panel:-       Click on the Desktop xampp icon  and click on...

Output function in PHP

PHP uses four different types of functions to display output. 1)  echo:-    It is used to print multiple statements using a PHP script. <?php echo "welcome","hello","xyz"; echo ("hello"); ?> it is mostly preferred to display output. 2) print:-    It is used to print a single statement using PHP Script. <?php print("welcome");   print "welcome"; ?> 3) printf():-    It is used to print formatted output means if we want to print data using format specifier %d,%f,%s then we can use printf() in PHP. we can print only a single statement using printf. <?php printf("%d",12.345)   //12 printf("%.2f",12.3456789)   //12.34 printf("%s","hello")  //hello ?> Another Example? <?php print 12.2345678;  //not possible till 2digit print("<br>"); echo 12.2345678,"<br>";    //not possible till 2digit printf("%.2f",12.2345678)  //possible...

Variable and Constant in PHP

Variable:-   It is the special identifier in PHP whose value can be changed. variable always will be declared using alphabets. PHP variable will be started from $ symbol. Syntax of Variable Declaration in PHP $identifier=value $a=10;       //Integer Type Variable $b="10";    //Numeric String $c = '10';   //Numeric String $d = 10.0;     //Float Value PHP provides a loosely coupled declaration for variable means no need to write data type on the variable declaration, it will be managed by assigned data.  using this concept we can use a single name variable for multiple values. $a=10; $a = "abc"; $a =True; mobile no = "9812311111"  //incorrect mobile_no= "981233444"  //correct 1a = 10   // incorrect a1=10  //correct note:-  space,numeric,keyword,capital letter,special char not allowed in variable declaration.  WAP to calculate Simple Interest ...

Operator Concept in PHP

It is used to perform operations using operand, Operand can be variable, constant, and literals. literal means value of variable or constant. for example, 1 is literals, "hello" is String literals. Type of Operator:- 1) Unary:-    This operator will work using a single operand. 1.1 Increment:-      $a++    increase by one 1.1.1  Post increment:-   first complete other operation then increase value.           $a++;          Example of Post Increment:-          <?php              $a=2;             $b=$a++;  //b=2,a=3             echo $a,"<br>",$b;           ?>    1.1.2  Pre Increment:- ...

Conditional Statement in PHP:-

It is used to solve a condition-based problem using If and Else Statement. If Statement will be executed when the condition will be true and else Statement will be executed when condition is false. Syntax of the conditional statement:- 1) Simple If:- if(condition) {      Statement; } WAP to print only even numbers? <?php $num=4; if($num%2==0) echo "Number is ",$num; ?> 2)  If--Else:- if(condition) {      Statement; } else {        Statement; } WAP to check the greater number? <?php $a=100; $b=20; if($a>$b) echo "$a is greater"; else { echo "$b is greater"; } ?> WAP to check two digits and three-digit numbers? <?php $num=12; if($num>=10 && $num<100)  echo "Two-Digit Number"; else {    if($num>=100 && $num<1000)     echo "Three Digit Number"; } ?> WAP to check two-digit negative numbers and positive numbers? 3) Nested if-...

Switch Statement In PHP:-

It is used to create option based or choice-based program.we can choose or select a particular option in options set. Switch contains multiple cases to define multiple options. switch(option)       //option==optionvalue {          case optionvalue:               optionstatement;               break;         case optionvalue:               optionstatement;               break;         case optionvalue:               optionstatement;               break;        default:           statement;           break; } WAP to display "yes","no" and "cancel"? <?php $op='L'; $option = (ord($op)>=65 && ord($o...

Loop Statement in PHP, for loop in PHP, while loop in PHP, do-while loop in PHP

Loop is used to print a large range of data using a single repeatable block.  Loop Statement Will work based on three different statements. 1)initialization:-   It is used to provide the starting point of the loop, for example, if we want to print 10 to 50 all data then the initialization point will be 10. $i=10; 2)condition:-    It is used to provide limit or the last point of the loop, for example, if we want to print 10 to 50 then the condition will be. $i<=50; 3)Iteration:-    It is used to increase or decrease the value of the loop. for example, if we want to display 10 to 50 but we want to increase value by 5 then we can use increment by five. $i=$i+5; Type of Loop:- 1)  Exit Control:-      "First Execute Loop Block Then Check Condition" for example if you first travel into the bus after that pay for the ticket then it is called Exit Control. do-while:-  It is called Exit Control Loop of PHP  Syntax:- init; do ...

Array Tutorials in PHP, Array in PHP

It is a collection of elements of the similar and dissimilar datatype, We can store element dynamically without providing size in PHP array. base index of the array will 0 to size-1, for example, the array has five elements then the array index will be started from 0 to 4. Advantage of Array:- 1)  We can store multiple elements using a single variable which is easy for program code. 2)  We can easily search and sort the elements   Type of Array:-   1)  Index Array:-  it will store data using an index where the base index will be started from 0 to size-1. $arrayname = array(12,23,34,11,56,67,78); $arrayname = array("c",12,23.45,"hello"); $arrayname[0]=12 ....

String in PHP

The string is a collection of char, String contains all data using a single stream. String indexing will be similar to an array, it will start from 0 to strlen()-1, strlen() is the predefined method that will return the total number of char in String. for example   $x = "hello"; echo $x; but indexing will be started from 0 to 4. echo $x[2];   //l in PHP We can declare String using a single quote ' ' and double quote " " both. Single quote string provides pure string value means the variable value will not be rendered. but double quote String " " provide normal string data means the variable value will be rendered. for example $x = 'abc '; echo '$x';   o/p $x $x= "abc"; echo "$x";     o/p abc ............................................................................................................................................... Predefine function of String:- 1) strlen() : -  it return String size    $x =...

How to take input from user's in PHP

How to take input from the user's in PHP:- To take input from the user's in PHP, We will Create HTML Form Element and get data from Text Filed, Button, etc. We will use get and post method to send data from the form element to Variable. HTML Provide complete forms and form elements to create a dynamic form using HTML. Step by Step Implementation for USER INPUT OPERATION IN PHP:- Step1st:-  Create AdditionDesign.php <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="AdditionLogic.php" method="post"> <input type="text" name="txtnum1" placeholder="Enter First Number" /> <br> <br> <input type="text" name="txtnum2" placeholder="Enter Second Number" /> <br> <br> <input type="submit" name="btnsubmit" value="Addition" /> </form> </body...

User's Input in PHP using Single File

We can write PHP Script under HTML page but extension should be .php.We can not write PHP Script under .html file because .html file contain only static data hence, if we want to write PHP Code script then the page extension should be .php. We can manage input operation in the same file. Complete Program of PHP:- Create .php file and write the below code under this. <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="" method="post"> <input type="text" name="txtnum1" placeholder="Enter First Number" /> <br> <br> <input type="text" name="txtnum2" placeholder="Enter Second Number" /> <br> <br> <input type="submit" name="btnsubmit" value="Addition" /> </form> <?php if(isset($_REQUEST['btnsubmit'])) { $num1 = $_REQUEST['txtnum1...

Date time and Mathematical function in PHP:-

Date time is the most important function of today programming because we always create logic for the expiration date, total duration, age calculation, time calculation PHP Provide in-built function for date and time:- 1)  date():-   it is a predefined function that provides the current date and time using different parameters. echo date('d')."<br>";  //return day index echo date('m')."<br>"; //return month index echo date('y')."<br>";  // return year last 2 digit echo date('D')."<br>"; //return day name echo date('M')."<br>"; // return Month name echo date('Y')."<br>";  //return complete year echo date('d-m-y')."<br>";  //return complete date date_default_timezone_set("Asia/Kolkata");   //change time zone  echo date('h')."<br>";   //return hours echo date('i')."<br>...

What is Include,Require,Include once and Require once in PHP?

Include and Include once:-  It is used to include the content of one PHP file to another PHP file, if the file not found then it will provide a warning and show the remaining data. If we include the same file multiple times then include will display multiple results but include_once will show single result. for example, if we create a.php file and echo "hello world" then if we include this file into b.php three times then it will display "hello world" three times but include_once will display "hello world" only once. Example of include PHP:- a.php code <?php echo "hello world"; ?> b.php  <?php rinclude("a.php"); include("a.php"); ?> output helloworld helloworld Example of includeonce PHP:- a.php code <?php echo "hello world"; ?> b.php  <?php rinclude_once("a.php"); include_once("a.php"); ?> output helloworld Require and Require once: -  It is used to include the conten...