Download presentation
Presentation is loading. Please wait.
1
PHP
2
What is PHP PHP stands for Hypertext Preprocessor. PHP is an interpreted language, i.e., there is no need for compilation. PHP is a server-side scripting language. PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use PHP is faster than other scripting languages, for example, ASP and JSP. The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.
3
What is a PHP File? PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code are executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php"
4
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
5
Why PHP? PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP supports a wide range of databases PHP is free. Download it from the official PHP resource: www.php.netwww.php.net PHP is easy to learn and runs efficiently on the server side
6
Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with : The default file extension for PHP files is ".php". A PHP file normally contains HTML tags, and some PHP scripting code.
7
Note: PHP statements end with a semicolon (;). My first PHP page
8
Comments in PHP A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code. Comments can be used to: Let others understand what you are doing Remind yourself of what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code
9
10
The most commonly and effective PHP syntax: 1234512345 <?php echo "Welcome to the world of php"; ?>
11
if you are using WAMP Server First you have to Set the short_open_tag setting in your php.ini file to on HTML script tags: echo "welcome to the world of php";
12
Web Development PHP is widely used in web development nowadays. PHP can develop dynamic websites easily. But you must have the basic the knowledge of following technologies for web development as well. HTML CSS JavaScript Ajax XML and JSON jQuery
13
PHP Case Sensitivity In PHP, NO keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are case-sensitive. In the example below, all three echo statements below are legal (and equal): "; echo "Hello World! "; EcHo "Hello World! "; ?>
14
However; all variable names are case- sensitive. Example "; echo "My house is ". $COLOR. " "; echo "My boat is ". $coLOR. " "; ?>
15
PHP Concatenation <?php $myCar = "Honda City"; echo $myCar." is riding"; ?>
16
Destroying PHP Variables To destroy a variable, pass the variable to PHP’s unset( ) function. as in the following example: <?php $name="steve"; echo $name; //unset( ) function destroy the variable reference. unset($name); ?>
17
Inspecting Variable Contents(Variable Property) <?php //define variables $name = "Fiona"; $age=25; //display variable contents var_dump ($name); var_dump($age); ?> Output string ‘Fiona’ (length=5) int 25
18
Difference Between $var and $$var in PHP PHP $$var uses the value of the variable whose name is the value of $var. It means $$var is known as reference variable where as $var is normal variable. It allows you to have a “variable’s variable” – the program can create the variable name the same way it can create any other string. variable <?php $name="Rajeev"; $$name="Sanjeev"; echo $name." "; echo $$name." "; echo $Rajeev; ?>
19
The PHP super global variables are : The PHP super global variables are : 1) $_GET[“FormElementName”] It is used to collect value from a form(HTML script) sent with method=’get’. information sent from a form with the method=’get’ is visible to everyone(it display on the browser URL bar). 2) $_POST[“FormElementName”] It is used to collect value in a form with method=”post”. Information sent from a form is invisible to others.(can check on address bar) 3) $_REQUEST[“FormElementName”] This can be used to collect data with both post and get method.
20
Super Global Variables in PHP 4) $_FILES[“FormElementName”] : It can be used to upload files from a client computer/system to a server. OR $_FILES[“FormElementName”][“ArrayIndex”] : Such as File Name, File Type, File Size, File temporary name. 5) $_SESSION[“VariableName”] A session variable is used to store information about a single user, and are available to all pages within one application. 6) $_COOKIE[“VariableName”] A cookie is used to identify a user. cookie is a small file that the server embedded on user computer.
21
Super Global Variables in PHP 7) $_SERVER[“ConstantName”] $_SERVER holds information about headers, paths, and script locations. eg. $_SERVER[“SERVER_PORT”], $_SERVER[“SERVER_NAME”], $_SERVER[“REQUEST_URI”]
22
PHP Constants PHP constants are name or identifier that can't be changed during the execution of the script. PHP constants can be defined by 2 ways: Using define() function Using const keyword PHP constants follow the same PHP variable rules. For example, it can be started with letter or underscore only. Conventionally, PHP constants should be defined in uppercase letters. <?php define('ConstName', 'value'); ?>
23
PHP constant: define() Let's see the syntax of define() function in PHP. define(name, value, case-insensitive) name: specifies the constant name value: specifies the constant value case-insensitive: Default value is false. It means it is case sensitive by default. <?php define("MESSAGE","Hello JavaTpoint PHP"); echo MESSAGE; ?> Output: Hello JavaTpoint PHP
24
PHP constant: const keyword The const keyword defines constants at compile time. It is a language construct not a function. It is bit faster than define(). It is always case sensitive. File: constant4.php 1.<?php 2.const MESSAGE="Hello const by JavaTpoint PHP"; 3.echo MESSAGE; 4.?> Output: Hello const by JavaTpoint PHP
25
PHP Magic Constant __LINE__The current line number of the file. __FILE__The full path and filename of the file. __FUNCTION__The function name __CLASS__The class name __METHOD__The class method name PHP_VERSIONThe PHP version PHP_INT_MAXThe PHP integer value limit PHP: Magic Constant
26
Difference between echo and print in PHP PHP echo and print both are PHP Statement. Both are used to display the output in PHP. Echo: echo is a statement i.e used to display the output. it can be used with parentheses echo or without parentheses echo. echo can pass multiple string separated as (, ) echo doesn’t return any value echo is faster then print <?php $name="John"; echo $name; //or echo ($name); ?>
27
Difference between echo and print in PHP Print Print is also a statement i.e used to display the output. it can be used with parentheses print( ) or without parentheses print. using print can doesn’t pass multiple argument print always return 1 it is slower than echo <?php $name="John"; print $name; //or print ($name); ?>
28
PHP data types Data types specify the size and type of values that can be stored. Variable does not need to be declared ITS DATA TYPE adding a value to it. Variable PHP is a Loosely Typed Language so here no need to define data type. To check only data type use gettype( ) function. To check value, data type and size use var_dump( ) function. for eg : variable contains integer, float, and string value
29
<?php $num=100; $fnum=100.0; $str="Hello"; var_dump($num,$fnum,$str); ?> Output int(100) float(100) string(5) “Hello” PHP data types
30
Data types in PHP There are 3 types of DATA TYPE Scalar(predefined) Compound(user-defined) Special type PHP data types
31
PHP Data Types: Scalar Types There are 4 scalar data types in PHP. boolean integer float string PHP Data Types: Compound Types There are 2 compound data types in PHP. array object PHP Data Types: Special Types There are 2 special data types in PHP. resource NULL
32
PHP Form Example PHP form is used to take input from users. in PHP if you want to take input from keyboard and display the output according to input, in that case you have to use html form. html form’s have a property : form method in which you have to set either get or post method. To illustrate, consider the following Web form(choose.php) which asks you to select a brand of automobile and enter your desired color.
33
PHP Script <?php error_reporting(1); $type=$_POST['selType']; $color=$_POST['txtColor']; echo " Your $color $type is ready. safe driving! "; ?>
34
PHP Form Handling We can create and use forms in PHP. To get form data, we need to use PHP superglobals $_GET and $_POST. The form request may be get or post. To retrieve data from get request, we need to use $_GET, for post request $_POST.
35
PHP Get Form Get request is the default form request. The data passed through get request is visible on the URL browser so it is not secured. You can send limited amount of data through get request. File: form1.html Name: File: welcome.php <?php $name=$_GET["name"];//receiving name field value in $name variable echo "Welcome, $name"; ?>
36
PHP Get Form GET method is unsecured method because it display all information on address bar/ url. By default method is get method. Using GET method limited data sends. GET method is faster way to send data.
37
PHP Post Form Post request is widely used to submit form that have large amount of data such as file upload, image upload, login form, registration form etc. The data passed through post request is not visible on the URL browser so it is secured. You can send large amount of data through post request. Let's see a simple example to receive data from post request in PHP.
38
PHP Post Form File: form1.html Name: Password: File: login.php <?php $name=$_POST["name"];//receiving name field value in $name variable $password=$_POST["password"];//receiving password field value in $password variable echo "Welcome: $name, your password is: $password"; ?>
39
PHP include and require Statements It is possible to insert the content of one PHP file into another PHP file (before the server executes it), with the include or require statement. PHP allows you to include file so that a page content can be reused many times. There are two ways to include file in PHP. include require Advantage Code Reusability: By the help of include and require construct, we can reuse HTML code or PHP script in many PHP scripts.
40
PHP include example PHP include is used to include file on the basis of given path. You may use relative or absolute path of the file. Let's see a simple PHP include example. File: menu.html Home | PHP | Java | HTML File: include1.php This is Main Page Output: Home | PHP | Java | HTML This is Main Page HomePHPJavaHTML
41
PHP include vs PHP require Use require when the file is required by the application. Use include when the file is not required and application should continue when file is not found. If file is missing or inclusion fails, include allows the script to continue but require halts the script producing a fatal E_COMPILE_ERROR level error.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.