Unit Iv
Unit Iv
What is PHP
o PHP stands for Hypertext Preprocessor.
o PHP is an interpreted language, i.e., there is no need for
compilation.
o PHP is faster than other scripting languages, for example, ASP and
JSP.
o PHP is a server-side scripting language, which is used to manage the
dynamic content of the website.
o PHP can be embedded into HTML.
o PHP is an object-oriented language.
o PHP is an open-source scripting language.
o PHP is simple and easy to learn language.
PHP Features
o PHP is very popular language because of its simplicity and open
source. There are some important features of PHP given below:
o Performance:
PHP script is executed much faster than those scripts which are
written in other languages such as JSP and ASP. PHP uses its own
memory, so the server workload and loading time is automatically
reduced, which results in faster processing speed and better
performance.
o Open Source:
PHP source code and software are freely available on the web. You
can develop all the versions of PHP according to your requirement
without paying any cost. All its components are free to download
and use.
o Familiarity with syntax:
PHP has easily understandable syntax. Programmers are
comfortable coding with it.
o Embedded:
PHP code can be easily embedded within HTML tags and script.
o Platform Independent:
PHP is available for WINDOWS, MAC, LINUX & UNIX operating
system. A PHP application developed in one OS can be easily
executed in other OS also.
o Database Support:
PHP supports all the leading databases such as MySQL, SQLite,
ODBC, etc.
o Error Reporting -
PHP has predefined error reporting constants to generate an error
notice or warning at runtime. E.g., E_ERROR, E_WARNING, E_STRICT,
E_PARSE.
o Loosely Typed Language:
PHP allows us to use a variable without declaring its datatype. It will
be taken automatically at the time of execution based on the type
of data it contains on its value.
o Web servers Support:
PHP is compatible with almost all local servers used today like
Apache, Netscape, Microsoft IIS, etc.
o Security:
PHP is a secure language to develop the website. It consists of
multiple layers of security to prevent threads and malicious attacks.
o Control:
Different programming languages require long script or code,
whereas PHP can do the same work in a few lines of code. It has
maximum control over the websites like you can make changes
easily whenever you want.
o A Helpful PHP Community:
It has a large community of developers who regularly updates
documentation, tutorials, online help, and FAQs. Learning PHP from
the communities is one of the significant benefits.
PHP Syntax
A PHP script is executed on the server, and the plain HTML result is sent
back to the browser.
<?php
// PHP code goes here
?>
A PHP file normally contains HTML tags, and some PHP scripting code.
PHP echo and print
Statements
With PHP, there are two basic ways to get output: echo and print.
In this tutorial we use echo or print in almost every example. So, this
chapter contains a little more info about those two output statements.
The differences are small: echo has no return value while print has a return
value of 1 so it can be used in expressions. echo can take multiple
parameters (although such usage is rare) while print can take one
argument. echo is marginally faster than print.
Display Text
The following example shows how to output text with the echo command
(notice that the text can contain HTML markup):
Example
<?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.";
?>
Display Text
The following example shows how to output text with the print command
(notice that the text can contain HTML markup):
Example
<?php
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>