Chapter 1 : PHP BasicsWhat is PHP
PHP is a open source server-side scripting language originally created by Rasmus Lerdorf in 1995 as "PersonalHome Page" but now the recursive acronym "PHP: Hypertext Preprocessor" is used to describe PHP currentfunctionality. Alternative server-side scripting languages to PHP include ASP, Java Servlets, Perl & Python.
What is PHP used for
PHP was designed to develop dynamic websites, but it can also be used for:
Server-side scripting (website development)
Command line scripting using cron (on Linux) or Task Scheduler (on Windows)
Writing desktop applications with a graphical user interface using PHP-GTK
Types of files you can create with PHP
With PHP you can generate any type as output including :
HTML, PDF , Flash movies (using libswf and Ming)
Text, such as XHTML and any other XML file
What you need to make PHP work
To make PHP work you need the PHP parser (CGI or server module), a web server and a web browser. ThePHP parser was re-written by Zeev Suraski and Andi Gutmans and re-named the Zend Engine. PHP can work with many database systems and servers..
How does PHP work
PHP code is embedded in files HTML files with the file extension .php. When a you request a web page writtenin PHP, the web browser send the request to the serve which then sends the PHP file to a PHP parser whichthen delivers the web document to the web browser for you to see.
You can install PHP manually or by using a pre-configured package like XAMP
Apache configuration file is called httpd.conf
PHP configuration file is php.ini
A PHP script always starts with <?php and ends with ?> or shorthand <? and end with ?>. A PHP file musthave a .php extension. The semicolon is used in PHP to tell one set of instructions from another, so each codeline in PHP must end with a semicolon. A statement represents an instruction to the PHP engine and usualyends with a semicolon. Exceptions to this include statements that enclose other statements and statements thatend a block of code.<?phpstatement;?>
Outputing text in PHP
There are two basic statements to output text with PHP: echo and print. Language constructs.1.print ()
print () is a language construct that behaves like a function and is used to outputs data. It acceptsa collection of characters (strings), which can be enclosed in single or double quotation marks. Itdoes not necessarily require parenthisis.2.echo ()
echo () is a language construct similar to the print () statement, it outputs data except that it doesnot return a value.
The famous “Hello World" in PHP
The 101 of learning any programming language is to know how to output “Hello World”<html><body><?php