introduction php
TRANSCRIPT
-
8/13/2019 Introduction Php
1/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 1 H.K.B.K.C.E
CHAPTER 1
INTRODUCTION
PHP is an "HTML-embedded scripting language" primarily used for dynamic Web
applications. The first part of this definition means that PHP code can be interspersed with
HTML, making it simple to generate dynamic pieces of Web pages on the fly. As a scripting
language, PHP code requires the presence of the PHP processor. PHP code is normally run in
plain-text scripts that will only run on PHP-enabled computers (conversely programming
languages can create standalone binary executable files, a.k.a. programs). PHP takes most of its
syntax from C, Java, and Perl. It is an open source technology and runs on most operating
systems and with most Web servers.
PHP (PHP: Hypertext Preprocessor) is a server-side scripting integrates with HTML to
create dynamic web pages. Because PHP a server-side scripting syntax and the PHP commands
will executed on the server and then the results are sent to the browser in HTML format. Thus
code written in PHP will not be visible to the user so that the web page security is guaranteed.
PHP is designed to form dynamic web pages, the web pages that can form a display based on
current demand, such as displaying the contents of a database to web pages.
PHP is included in the Open Source Product, making PHP source code can be changed
and distributed freely. The latest version of PHP can be downloaded for free at PHP official
website: http://www.php.net. PHP can run on a variety of web servers such as IIS (Internet
Information Server), PWS (Personal Web Server), Apache, Xitami, etc... PHP is also capable of
cross-platform. This means that PHP runs on Windows Operating System and some versions of
Linux, and PHP can be built as a module on Apache web server and as a binary that can run as
a CGI (Common Gateway Interface). PHP can send the HTTP header, can set cookies, manage
authentication, and redirect users. One of the advantages possessed by PHP is its ability to
connect to a wide range of database software, so it can create dynamic web pages.
PHP supports communication with other services via the IMAP protocol, SNMP,
NNTP, POP3 or HTTP. When PHP is in your web page, it is no longer needed development the
special circumstances or special directories. Almost all web-based applications can made with
PHP. But the main strength is connectivity with database web. With this capability we will
have a database system that can be accessed from the web.
-
8/13/2019 Introduction Php
2/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 2 H.K.B.K.C.E
CHAPTER 2
HISTORY
PHP was written in the C programming language by Rasmus Lerdorf in 1994 for use in
monitoring his online resume and related personal information. For this reason, PHP originally
stood for "Personal Home Page". Lerdorf combined PHP with his own Form Interpreter,
releasing the combination publicly as PHP/FI (generally referred to as PHP 2.0) on June 8,
1995. Two programmers, Zeev Suraski and Andi Gutmans, rebuilt PHP's core, releasing the
updated result as PHP/FI 2 in 1997. The acronym was formally changed to PHP: Hypertext
Preprocessor, at this time. (This is an example of a recursive acronym: where the acronym itself
is in its own definition.) In 1998, PHP 3 was released, which was the first widely used version.
PHP 4 was released in May 2000, with a new core, known as the Zend Engine 1.0. PHP 4
featured improved speed and reliability over PHP 3. In terms of features, PHP 4 added
references, the Boolean type, COM support on Windows, output buffering, many new array
functions, expanded object-oriented programming, inclusion of the PCRE library, and more.
Maintenance releases of PHP 4 are still available, primarily for security updates.
PHP 5 was released in July 2004, with the updated Zend Engine 2.0. Among the many
new features in PHP 5 are:
improved object-oriented programming embedded SQLite and support for new MySQL features Exception handling using a try...catch structure integrated SOAP support (see the image at right) the Filter library (in PHP 5.1) better XML tools iterators and much, much more.
PHP 6 has been in development since October of 2006. The most significant change
will be native support for Unicode. Unpopular, deprecated features such as Magic Quotes,
register_globals, safe_mode, and the HTTP_*_VARS variables will disappear in PHP 6.
Although PHP is still primarily used for server-side generation of Web pages, it can also be
used to perform command-line scripting or to create graphical applications with the help of
GTK+
-
8/13/2019 Introduction Php
3/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 3 H.K.B.K.C.E
CHAPTER 3
KNOW YOUR PHP SCRIPT
PHP scripts are included in HTML-embedded, which means PHP code can be inserted
on an HTML page. A PHP script always starts with . A PHP script can
be placed anywhere in the document. On servers with shorthand-support, you can start a PHP
script with . The first way is the format recommended; it may be a second
way is often used because it is more concise. The third way is used to anticipate that editors can
not receive both of the above. Moreover we can also use ASP prose, but of course there is some
configuration that needs to be done.
A PHP file must have a .php extension. A PHP file normally contains HTML tags, and some
PHP scripting code.
Below, we have an example of a simple PHP script that sends the text "Hello World" back to
the browser:
Each code line in PHP must end with a semicolon. The semicolon is a separator and is used todistinguish one set of instructions from another.
PHP Parser works read HTML files to find specific markers that tell you to translate the
following script as PHP code. Parser PHP would execute all of the commands in the PHP code
block. In this way the code is PHP script can be embedded in an HTML document. Other text
blocks that are beyond the PHP script will be treated as regular HTML.
-
8/13/2019 Introduction Php
4/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 4 H.K.B.K.C.E
Here is a simple example of the use of the PHP language inserted in the HTML
first PHP script
There are two basic statements to output text with PHP: echoand print.
In the example above we have used the echo statement to output the text "Hello World".
-
8/13/2019 Introduction Php
5/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 5 H.K.B.K.C.E
CHAPTER 4
VARIABLES
In any programming language we will surely encounter the concept of variables.
Variable is a place in memory to store data whose value can be changed during the program
run. But unlike in most languages other programming that requires us to declare variables prior
first, a variable in PHP does not have to be declared before the variable is used. Variable
represented by a particular word with the rules of writing as the following:
1. Variables begin with a dollar sign ($).2. Must begin with a letter or an underscore (_).3. May not use punctuation.4. Case sensitive (or uppercase and lowercase letters are different).5. Do not use words that are built-in PHP functions.
CREATING (DECLARING) PHP VARIABLES
PHP has no command for declaring a variable. A variable is created the moment you
first assign a value to it:
$myCar="Volvo";
After the execution of the statement above, the variable myCarwill hold the value Volvo.
PHP is a Loosely Typed Language. In PHP, a variable does not need to be declared
before adding a value to it. In the example above, notice that we did not have to tell PHP which
data type the variable is. PHP automatically converts the variable to the correct data type,
depending on its value. In a strongly typed programming language, you have to declare (define)
the type and name of the variable before using it.
PHP VARIABLE SCOPE
The scope of a variable is the portion of the script in which the variable can be
referenced.
-
8/13/2019 Introduction Php
6/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 6 H.K.B.K.C.E
PHP has four different variable scopes:
local global static parameter
1. LOCAL SCOPEA variable declared within a PHP function is local and can only be accessed
within that function. You can have local variables with the same name in different functions,
because local variables are only recognized by the function in which they are declared. Local
variables are deleted as soon as the function is completed.
2. GLOBAL SCOPEGlobal scope refers to any variable that is defined outside of any function.
Global variables can be accessed from any part of the script that is not inside a function. To
access a global variable from within a function, use the global keyword.
PHP also stores all global variables in an array called $GLOBALS[index]. Its index is
the name of the variable. This array is also accessible from within functions and can be used to
update global variables directly.
3. STATIC SCOPEWhen a function is completed, all of its variables are normally deleted.
However, sometimes you want a local variable to not be deleted. To do this, use
the static keyword when you first declare the variable. Then, each time the function is called,
that variable will still have the information it contained from the last time the function was
called.
4. PARAMETERSA parameter is a local variable whose value is passed to the function by the calling code.
Parameters are declared in a parameter list as part of the function declaration. Parameters are
also called arguments. We will discuss them in more detail when we talk about functions.
-
8/13/2019 Introduction Php
7/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 7 H.K.B.K.C.E
CHAPTER 5
CONSTANTS
The constant is a variable whose value is fixed. Constants are only rated at the
beginning of the program and its value never changes during the program. PHP has defined
some constants, e.g.: PHP_VERSION, the constant that provides information about the version
of PHP you are using. In addition to the constants that have been provided by the PHP we can
also create our own constants. Rules of writing constants are as follows:
define (name_constant"," value_constant ")
Examples of the use of constants:
Using constants
-
8/13/2019 Introduction Php
8/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 8 H.K.B.K.C.E
CHAPTER 6
DATA TYPES
PHP to know some of the data types are: integer, floating point, and string. Floating point better
known as double or decimal. Writing string always begins with double quotation marks (") or
single quotes (').
Examples of writing data type is as follows:
Example Data Type Specification
Integer $ number = 10; Integers
$ Value = -5;
Double $ score = 90.00; Numbers real
$ Rate = 12:50;
String $ city = "Bangalore" Character, sentence
$ Motto = "Cozy"
-
8/13/2019 Introduction Php
9/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 9 H.K.B.K.C.E
CHAPTER 7
OPERATORS
Operators are symbols that are used to manipulate data, such as addition, subtraction,
multiplication, comparison, or assignment. There are operators which uses a single operand
there is also the two operands. Operands and operators together form an expression.
Operators can be grouped into four categories, namely:
1. Arithmetic operator is the operator associated with the function mathematics.2. The operator is an operator that compares the logic of TRUE and FALSE.3. Bitwise operators are binary operators to compare.4. There are also operators that are often used but are not included in the above, we can
learn it in other groups.
ARITHMETIC OPERATORS
Arithmetic operator is an operator associated with the function mathematics. This
operator we use in the program that we will create.
Operator Operation
+ Addition
- Reduction
* Multiplication
/ Distribution
% The rest of the division
+ + Addition to 1
- - Reduction by 1
LOGIC OPERATORS
This operator will compare the TRUE or FALSE. Like the C language, PHP defines
True and False with 0 to 1.
-
8/13/2019 Introduction Php
10/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 10 H.K.B.K.C.E
Operator Operation
== Same
! = Not equal to
< Smaller
> Greater than
= Greater same
AND or && Logical AND
OR or | | Logical OR
XOR logic XOR
! Logical NOT
BITWISE OPERATORS
These operators are used to manipulate the bits of the value of the data. Operator and its
meaning can be seen in the following table:
Operator Operation
>> Shifting bits to the right
-
8/13/2019 Introduction Php
11/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 11 H.K.B.K.C.E
CHAPTER 8
CONTROL STRUCTURE
Flow control structure is a control program, has a series of commands that must be
written to meet several conditions, namely:
Repeating a command if a condition is met.
Continuing a statement when acondition is met.
Choose an option from several alternatives if conditions are met.
Control structure can be divided into two types, namely branching control structures
(decision making) and repetition control structures (loops).
FULL BRANCHING STRUCTURE
Branching control structures (decision making) control structure serves to make the
selection of the command to be executed in accordance with certain conditions. There are four
branching command in PHP, that is if, if.. else, if ..elseif, and switch.
_ Command if
If is the command is used to execute one or more commands based on a condition. If
syntax of the command is as follows:
if (condition)
{
statements to be executed if the condition is true
}
In this form, the statement will be executed only if the condition part is true. Here is an example
of using the control structure if:
Control Structures IF
-
8/13/2019 Introduction Php
12/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 12 H.K.B.K.C.E
_ Command if ... else
If ... else command is used to select one of the statements based on a condition. This
command will execute a statement if a certain condition is true and will execute another
statement if the condition is false. The syntax is written as follows:
if (condition)
{
statement_1
}
Else
{
statement_2
}
-
8/13/2019 Introduction Php
13/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 13 H.K.B.K.C.E
In this form statement_1 executed if that condition is true, and statement_2 run when
condition is false. Example use if ... else statement, as follows:
Control Structure IF ... ELSE
REPETITION CONTROL STRUCTURE
The structure of the control loop is used to repeat a command many times as desired.
There are three types of repetition in the PHP commands, namely, for, while, and do ... while.
-
8/13/2019 Introduction Php
14/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 14 H.K.B.K.C.E
_ Command for.
Command for is used to repeat a command by the number of repetitions is already
known. In this command does not need to write a condition for tested. We just need to write
down the value of the beginning and end of the counter variable. Value counter variable will be
automatically increased or decreased each time a repetition is performed. Syntax of the
command for the following:
for (value_begin; value_end; addition / subtraction)
{
statement is executed
}
Examples of repetition with the for structure:
structure with a FOR loop
-
8/13/2019 Introduction Php
15/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 15 H.K.B.K.C.E
_ Command do ... while
With orders do ... while, the loop will continue to be done if the conditions are checked
in while they are true. An iterative process will be stopped if the condition is false already.
Writing the following syntax:
do
{
statement is executed
}
while (condition);
-
8/13/2019 Introduction Php
16/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 16 H.K.B.K.C.E
CHAPTER 9
ARRAYS
Array is a facility to store data sequentially. Data stored in the array by using an index
to facilitate retrieval of data. Unlike the variable can only store a single value, the array is able
to accommodate a number of values.
ARRAY DECLARATION
The data contained in the array are called array elements and the location of each
sequence each element of the array is indicated by an index. Array has limits
upper and lower limits, where the data is stored between the two limits. All elements of the
array are stored has the same data type. Arrays can be dimensional one, two, three or more.
One-dimensional array (one-dimensional array) represent the shape of a vector. Two-
dimensional array (two-dimensional array) represents the form of a matrix. Three-dimensional
Array represent the shape of a space.
Some ways to declare an array:
Using Array
-
8/13/2019 Introduction Php
17/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 17 H.K.B.K.C.E
$ Color = array ("red", "yellow", "green", "blue");
print ("The first array declaration
:
"), print ($ color [2]);# How to declare a second array $ cities [] = "New York";
$ Cities [] = "London";
$ Cities [] = "Delhi";
$ Cities [] = "Tokyo";
$ Cities [] = "Bangalore";
$ Cities [] = "Jogjakarta";
print ("The second array declaration
:
"), print ($ city [5]);# How to declare a third array $ city [0] = "New York";
$ Cities [5] = "London";
$ Cities [2] = "Delhi";
$ Cities [] = "Tokyo";
$ Cities [] = "Bangalore";
$ Cities [gudeg] = "Jogjakarta";
print ("
third array declaration:
") print ("$ city [5]
");print ("$ city [7]
");print ("I am currently studying at $ cities [gudeg]");
?>
-
8/13/2019 Introduction Php
18/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 18 H.K.B.K.C.E
CHAPTER 10
FUNCTIONS
In making our programs often require a set of commands that will be used repeatedly.
Obviously very troublesome if the commands have to re-type every time it is used. This can be
avoided by using subroutines. Subroutine is a set of commands that are named and then we can
call any time. In programming there are two kinds of subroutines, the procedures and functions.
The difference between these two kinds of subroutines is, the function returns a value
particular, while procedures do not. PHP language only know the command to making function,
that function. In a subroutine required argument, namely values that must be entered when the
subroutine is called. But not worry we can make the procedure using the command function but
not using the return command. The command return is used to return a certain value. The
standard of writing functions are:
Name_function Function (arguments)
{
command code
}
Here is an example of using either function using the command return or not to use the
command returns, the results.
Examples of programs without command returns:
Make no command function returns
-
8/13/2019 Introduction Php
19/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 19 H.K.B.K.C.E
function store ()
{
print ("www.flipkart.com
cheapest online shopping");}
store ();
?>
FUNCTION WITH ARGUMENT
The argument is a value that is put into a function. By default the arguments are passed
by value, which means that only the value that is needed so that the value of the variable does
not change after the function is executed. Consider the following examples:
function with argument passed by value
-
8/13/2019 Introduction Php
20/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 20 H.K.B.K.C.E
?>
In addition to the arguments mentioned above, there are also arguments that are passed
by reference, which is used when we want to change the value of an argument. Arguments are
passed by reference it will change its value after the function executed. To make the argument
passed by reference we will use character "&" in front of the argument. For more details, see
the example the following:
function with arguments passed by reference
-
8/13/2019 Introduction Php
21/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 21 H.K.B.K.C.E
BUILT-IN FUNCTIONS
This section will discuss the functions provided by PHP. We can also learn other
functions in the various manuals are widely available on the internet.
_ Public Functions
echo string_first, string_second, .. string_last
Echo function is often used to send one or more parameters, separated by punctuation comma
(,) to the browser. For example:
echo Function
-
8/13/2019 Introduction Php
22/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 22 H.K.B.K.C.E
printf (string_format, arguments ...)
This function is almost the same as the print function, which is to send output to the
browser.
This function is often used to display the results in a format which can be arranged.
Format Specification
D Integer, decimal notation
B Integer, binary notation
O Integer, octal notation
X Integer, hexadecimal notation, expressed in lowercase
X Integer, hexadecimal notation, stated in capital letters
C character ASCII value of its stated preformance argument
S String
F Double (real number)
Examples of the use of the printf function is:
printf function
-
8/13/2019 Introduction Php
23/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 23 H.K.B.K.C.E
copy (string_source, string_destination)
This function is used to copy a file specified in the argument source (origin location
file) to the destination (destination). Will yield true if successful
copy function
-
8/13/2019 Introduction Php
24/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 24 H.K.B.K.C.E
include (string_filename)
The argument filename is the name of the file to be executed with the include. This
function is often used to insert the file mentioned in the argument. Observe the example below:
Functions include
phpinfo ()
This function will get the information about the version of PHP, the author, the
operating system on the web server, the configuration variables, and so on. Example:
function phpinfo ()
-
8/13/2019 Introduction Php
25/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 25 H.K.B.K.C.E
?>
phpversion ()
This function will only provide information about the PHP version that we use.
phpversion function ()
strlen (string_text)
This function will return an integer value which is the length of the string in the
argument text. See the following example:
strlen function
-
8/13/2019 Introduction Php
26/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 26 H.K.B.K.C.E
?>
ord (string_character)
This function will return a value of ASCII characters in the argument. So the argument
is just a character. Consider the example below:
function ord
strtolower (string_text)
This function will change the argument to lowercase all. For details you can try the
following example:
strtolower function
-
8/13/2019 Introduction Php
27/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 27 H.K.B.K.C.E
Strtoupper (string_text)
This function is the inverse of the function strtolower. All the letters in the text
argument of type string is converted to uppercase and to be output from this function. Consider
the example below:
strtoupper function
_ Function Date and Time
date (string_format, integer_timestamp)
Date function returns the date or time depending on the arguments you entered.
String_format list contained in the table below. Timestamp argument is optional.
-
8/13/2019 Introduction Php
28/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 28 H.K.B.K.C.E
Code Description
a am or pm
A AM or PM
d Date (date)
D Name Day (short)
F Name month
H Hours 01 to 12
H Hour 00 to 23
I Minute
A Date
L Name Day (complete)
M Month (in numbers)
M Moon (short)
Y Year in two digits
Y year in four digits
Z Day of the year
Consider an example:
Function date
-
8/13/2019 Introduction Php
29/48
-
8/13/2019 Introduction Php
30/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 30 H.K.B.K.C.E
elseif ($ time [hours]
-
8/13/2019 Introduction Php
31/48
-
8/13/2019 Introduction Php
32/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 32 H.K.B.K.C.E
MATHEMATICAL FUNCTIONS
abs (NUMBER_VALUE)
This function will return the value of the absolute value of the argument. If the value of
the argument is positive, then the abs function returns the value itself. If the argument value is
negative, abs function will multiply the argument by negative one (-1). Consider the following
example:
Function abs
cos (double_angle)
This function will return the cosine of the angle value (in radians). Consider the
example below:
function cos
-
8/13/2019 Introduction Php
33/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 33 H.K.B.K.C.E
exp (double_power)
This function will return the value of the exponent of the argument. See the following
example:
exp function
pow (double_base, double_power)
This function is used to generate the value of the base power value in power. Consider the
following examples:
-
8/13/2019 Introduction Php
34/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 34 H.K.B.K.C.E
function pow ()
round (double_value)
This function changes the value of the argument (of type double) to the nearest integer
(rounding). Consider the following examples:
function round ()
-
8/13/2019 Introduction Php
35/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 35 H.K.B.K.C.E
sin (double_single)
This function produces the value of the sine of the angle value (in radians) of the
argument. Consider the following examples:
function sin ()
sqrt (double_value)
This function is used to find the value of the root of the argument value. Consider the
following examples:
function sqrt ()
-
8/13/2019 Introduction Php
36/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 36 H.K.B.K.C.E
tan (double_angle)
This function will generate the value of the tangent of the angle (in radians) the angle
argument. Consider the following examples:
function tan ()
function define ()
-
8/13/2019 Introduction Php
37/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 37 H.K.B.K.C.E
This function will return true if the variable does not have any value, and otherwise
false if the variable has been given a value. Consider the following example
:
function empty ()
is_array (expression)
This function will return true if the expression is an array, and false otherwise. Consider
the following examples:
function is_array ()
-
8/13/2019 Introduction Php
38/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 38 H.K.B.K.C.E
is_double (expression)
This function will return true if the value of the expression of type double. Consider the
following examples:
is_double function ()
-
8/13/2019 Introduction Php
39/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 39 H.K.B.K.C.E
is_integer (expression)
This function will return true if the value of the expression of type integer. Consider the
following examples:
is_integer function ()
is_string (expression)
This function will return true if the value of the expression of type string Consider the
following examples:
-
8/13/2019 Introduction Php
40/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 40 H.K.B.K.C.E
function is_string ()
isset (variable)
This function will return true if the variable already has a value, and otherwise false if
the variable is not yet rated. Consider the following examples:
function isset ()
-
8/13/2019 Introduction Php
41/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 41 H.K.B.K.C.E
else
{
print ("Please fill your name soon!");
}
?>
count (variable_array)
This function will return the value in the number of array elements of the argument
variable. If the variable has not been filled then the function will return a value of 0. If
variable is not an array, the function will return the value 1. Consider the following examples:
function count ()
-
8/13/2019 Introduction Php
42/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 42 H.K.B.K.C.E
CHAPTER 11
INCLUDE AND REQUIRE
Did require () and include () it's really the same as how it works? Of course not, because if the
same function would not properly differentiated function. The fundamental difference between
these two functions is:
Functions require() will always be replaced by the contents of the file referred to in
this function and can not be used in the branching because the designated file will
always referenced no matter the condition of the structure / flow of the script.
Functions include () will set the reading of the file can be designated in accordance
with the condition of the structure / flow of the script, so that this function can be used in
branching.
Seeing the characteristics above, require () will be used to reference the appropriate file
containing variables and global functions that are used in all parts of the main script. While
include () is commonly used to insert code / script or HTML tag on the program / main script,
e.g. for the header or footer of each page in a site.
Important to note that both of these functions, the PHP parser will leave PHP mode and
return to the default HTML mode when reading a file shown by these two functions. That is
why in the above example, all files designated by these functions always begin with the To return the file mode to mode PHP script.
-
8/13/2019 Introduction Php
43/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 43 H.K.B.K.C.E
CHAPTER 12
EVOLUTION
One of the basic features of PHP/FIwas a Perl-like language for handling form submissions,
but it lacked many common useful language features, such as for loops.
PHP/FI 2
A rewrite came with PHP/FI 2 in 1997, but at that time the development was almost
solely handled by Rasmus. After its release in November of that year, Andi Gutmans and Zeev
Suraski bumped into PHP/FI while looking for a language to develop an e-commerce solutionas a university project. They discovered that PHP/FI was not quite as powerful as it seemed,
and its language was lacking many common features. One of the most interesting aspects
included the way while loops were implemented. The hand-crafted lexical scanner would go
through the script and when it hit the while keyword it would remember its position in the file.
At the end of the loop, the file pointer sought back to the saved position, and the whole loop
was reread and re-executed.
PHP 3
Zeev and Andi decided to completely rewrite the scripting language. They then teamed
up with Rasmus to release PHP 3, and along also came a new name: PHP: Hypertext
Preprocessor, to emphasize that PHP was a different product and not only suitable for personal
use. Zeev and Andi had also designed and implemented a new extension API. This new API
made it possible to easily support additional extensions for performing tasks such as accessing
databases, spell checkers and other technologies, which attracted many developers who were
not part of the "core" group to join and contribute to the PHP project. At the time of PHP 3s
release in June 1998, the estimated PHP installed base consisted of about 50,000 domains. PHP
3 sparked the beginning of PHPs real breakthrough, and was the first version to have an
installed base of more than one million domains.
-
8/13/2019 Introduction Php
44/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 44 H.K.B.K.C.E
PHP 4
While PHP 3 still continuously parsed the scripts while executing them, PHP 4 came
with a new paradigm of "compile first, execute later." The compilation step does not compile
PHP scripts into machine code; it instead compiles them into byte code, which is then executed
by the Zend Engine (Zend stands for Zeev & Andi), the new heart of PHP 4. Because of this
new way of executing scripts, the performance of PHP 4 was much better than that of PHP 3,
with only a small amount of backward compatibility breakage.
The first important change came in PHP 4.1.0, which introduced superglobals such as
$_GET and $_POST. Superglobals can be accessed from within functions without having to
use the global keyword. With the new superglobals in place, on April 22, 2002, PHP 4.2.0 was
released with the register_globals turned off by default. PHP 4.3.0, the last significant PHP 4
version, was released on December 27, 2002. This version introduced the Command Line
Interface (CLI), a revamped file and network I/O layer (called streams), and a bundled GD
library. Although most of those additions have no real effect on end users, the major version
was bumped due to the major changes in PHPs core.
PHP 5
Soon after, the demand for more common object-oriented features increased immensely,
and Andi came up with the idea of rewriting the objected-oriented part of the Zend Engine.
Zeev and Andi wrote the "Zend Engine II: Feature Overview and Design" document and
jumpstarted heated discussions about PHPs future. Although the basic language has stayed the
same, many features were added, dropped, and changed by the time PHP 5 matured.
PHP 5 is expected to maintain and even increase PHPs leadership in the web
development market. Not only does it revolutionize PHPs object oriented support but it also
contains many new features which make it the ultimate web development platform.
The rewritten XML functionality in PHP 5 puts it on par with other web technologies in
some areas and overtakes them in others, especially due to the new SimpleXML extension
which makes it ridiculously easy to manipulate XML documents. In addition, the new SOAP,
MySQL, and variety of other extensions are significant milestones in PHPs support for
additional technologies. Still works are going on for PHP6.
-
8/13/2019 Introduction Php
45/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 45 H.K.B.K.C.E
CHAPTER 13
APPLICATIONS
PHP can work for the creation of many types of interactive applications. It can be used for the
creation of forums, private messaging services and recommendations to people who use a site
on a regular basis.
Meanwhile, some online shopping functions can be handled with the PHP language. These
include shopping carts for people who want to buy things and recommendations for other
products that people can buy. These recommendations will be based on prior purchases that
customers have made.
Purchases and hits on a site can be tracked with PHP as well. This is done with absolute value,
rounding and square root calculations. These math functions can work in PHP to calculate
different things that are going on with a site.
Another function is that the language can work with interactivity with a server in mind. This
comes from how PHP is a server side language. It only gives out client details when the client
itself gives the details to the server. Therefore, the PHP language can work for processes that
involve integrating databases into websites or getting dynamic text to work alongside static text
on a site.
PHP will work with any type of server that it is reached on. This comes from how it is an open
source language. Therefore, this language is more portable than others.
-
8/13/2019 Introduction Php
46/48
HYPERTEXT PREPROCESSOR
Dept. of ECE 46 H.K.B.K.C.E
CHAPTER 14
ADVANTAGES AND DISADVANTAGES
ADVANTAGES:
Open Source, readily available (you can be using it today) and dual- licensed - if youare doing non-profit work or not licensing, there is no cost.
Very Easy to understand Syntax, some really cool features (arrays are something else!) Interfaces very easily with Apache/MySQL Server side (no need to futz with client installs - only with rendering issues if you use
CSS).
Lots of good source code out there to use and/or learn fom, as well as many usefullibraries for working with PDFs, graphics, etc.
Lots of good books and on-line help (php.net is great)Platform agnostic, can run on Windows Linux or Mac servers. Also very scalable.
Lots of hosting services have it ready to use, no special configuration (except if you
have special security needs)
Pretty easy to access other web-based tools through PHP (i.e. google maps, etc.)DISADVANTAGES
If you want to do more than just HTML/CSS pages on the client you need to also addjavascript, java or other client-side language in your output (goes for Perl and some
other languages).
The way browsers work make handling data and coding programs more interesting(technically each page is a new run on the system, so you have to manage your
variables coming in and going out and between pages. Not hard, just different.)
Web programming (regardless of language) is open to security flaws due tounimplemented or unknown vulnerabilities, takes a bit more caution.
-
8/13/2019 Introduction Php
47/48
-
8/13/2019 Introduction Php
48/48
HYPERTEXT PREPROCESSOR
Disadv
Security : Since it is open sourced, so all people can see the source code, if there are bugs inthe source code, it can be used by people to explore the weakness of PHP
Not suitable for large applications: Hard to maintain since it is not very modular.