Unit 1
Unit 1
BASICS OF PHP
What is PHP?
•PHP files can contain text, HTML, CSS, JavaScript, and PHP code
•PHP code is executed on the server, and the result is returned to the browser as plain HTML
•PHP can create, open, read, write, delete, and close files on the server
You can separately install Web Server, PHP Interpreter, and MySQL databases, but
to make work easier, developers have made all in one setup packages
called WAMP, LAMP, MAMP, and XAMPP, which will automatically install and set up
PHP environment on your Windows, Linux or MAC machines.
The official PHP website (PHP.net) has installation instructions for PHP:
http://php.net/manual/en/install.php
Basic PHP Syntax
With PHP, there are two basic ways to get output: echo and print.
• echo and print are more or less the same. They are both used to output data to the screen.
• 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.
The PHP echo Statement
The echo statement can be used with or without parentheses: echo or echo().
The PHP print Statement
The print statement can be used with or without parentheses: print or print().
PHP Variables
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume).
Rules for PHP variables:
•A variable starts with the $ sign, followed by the name of the
variable
•A variable name must start with a letter or the underscore
character
•A variable name cannot start with a number
•A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
•Variable names are case-sensitive ($age and $AGE are two
different variables)
Variables are "containers" for storing information.