05_PHP_Lecture
05_PHP_Lecture
05_PHP_Lecture
iFour Consultancy
HYPERTEXT PREPROCESSOR
web Engineering ||
winter 2017
wahidullah Mudaser Lecture 05
assignment.cs2017@gmail.com
Introduction To PHP
INDEX
Three-tiered website
Introduction to PHP
Server side scripting langauge
response PHP
Database
MySQL
Server Side Scripting Language
In server-side scripting, (such as PHP, ASP) the script is processed by the server Like: Apache,
ColdFusion, ISAPI and Microsoft's IIS on Windows.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive
Web pages.
PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's
ASP.
PHP is an acronym for "PHP: Hypertext Preprocessor"
PHP is a widely-used, open source scripting language
PHP scripts are executed on the server
PHP is free to download and use
Cont…
PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in 1994. It was initially developed for HTTP usage logging and server-
side form generation in Unix.
PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables,
arrays, recursive functions, conditionals, iteration, regular expressions, etc.
PHP 3 (1998) added support for ODBC data sources, multiple platform support, email protocols (SNMP,IMAP), and new parser written by
Zeev Suraski and Andi Gutmans .
PHP 4 (2000) became an independent component of the web server for added efficiency. The parser was renamed the Zend Engine. Many
security features were added.
PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for
interoperability with Web Services, SQLite has been bundled with PHP
What is PHP File
<!DOCTYPE html>
<html>
<body>
<h1>PHP TUTORIAL</h1>
<?php
echo “YCCE NAGPUR”;
?>
</body>
</html>
PHP Variables
<?php
function myTest() {
static $x = 0;
echo $x;
$x++;
}
myTest();
myTest();
myTest();
?>
PHP echo Statement
<?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.";
?>
PHP print statement
<?php
$txt1 = "Learn PHP";
$txt2 = “ycce.com"; Echo V.S Print
$x = 5; The differences are small: echo has no return value while
$y = 4; print has a return value of 1 so it can be used in expressions.
PHP String:
A string is a sequence of characters, like "Hello world!".
A string can be any text inside quotes. You can use single
or double quotes:
Example
<?php
$x = 5985;
var_dump($x);
?>
Cont…
PHP Array:
<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
PHP Object
An object is a data type which stores data and information on
how to process that data.
In PHP, an object must be explicitly declared.
<?php
class Car {
function Car() {
$this->model = "VW";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?>
PHP NULL value
Null is a special data type which can have only one value:
NULL.
A variable of data type NULL is a variable that has no
value assigned to it.
Note: If a variable is created without a value, it is
automatically assigned a value of NULL.
Example
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
PHP String Functions
Get The Length of a String:
Example
<?php
echo strlen("Hello world!"); // outputs 12
?>
Cont…
Reverse a String:
Example
<?php
echo strrev("Hello world!");
?>
Cont…
Search For a Specific Text Within a String:
If a match is found, the function returns the character
position of the first match. If no match is found, it will
return FALSE.
Example
<?php
echo strpos("Hello world!", "world"); // outputs 6
?>
Cont…
<?php
define(“NAME", "Welcome Ahmadullah!");
echo NAME;
?>
Constants are Global:
<?php
define(“NAME", "Welcome Ahmadullah!");
function myTest() {
echo NAME;
}
myTest();
?>
PHP Operators
Operators are used to perform operations on variables and
values.
Arithmetic operators
Assignment operators
Comparison operators
Increment/Decrement operators
Logical operators
String operators
Array operators
PHP Operators