PHP Introduction and Examples
PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient in developing web applications.
- PHP stands for Hypertext Preprocessor
- PHP is a server-side scripting language, like ASP
- PHP scripts are executed on the server
- PHP supports many databases (MySQL, Oracle, PostgreSQL, etc.)
- PHP is an open source software
- PHP is free to download and use
- PHP files can contain text, HTML tags and scripts
- PHP files are returned to the browser as plain HTML
- PHP files have a file extension of “.php”, “.php3”, or “.phtml”
- PHP programs start with “” tag. e.g:
- HTML can be written inside a PHP code block just like JSP and Servlets in Java
- PHP runs on different platforms (Windows, Linux, Unix, etc.)
- PHP is compatible with almost all servers e.g. apache, IIS, etc.
- PHP official website is: www.php.net
- PHP is easy to learn and runs efficiently on the server side
How to start with PHP?
1. Download and Install WAMP SERVER. Click here to download.
2. Create and store your php files in the www directory of installed wamp server which can be generally found in c:// drive or in the drive where you have installed the wamp server.
3. Start the wamp server
4. Click on the tray icon of wamp server and after the pop up menu appears click on the localhost option.Example Program 1:
1. save this file as index.php
2. put the file index.php in a folder name first
3. now move the folder to www directory of wamp server
4. start the wamp server
5. click on the tray icon of wamp server
6. click on localhost from the pop appeared
7. click on the folder “first” listed under heading “your projects”
8. You can see the output now.
Output of index.php : Hello World in PHP!Hello World!
echo is used for printing or displaying data in php we can use ‘Hello World!’ (single quotes) or “Hello World” (double quotes).
Example2 : variable.php
"; echo $variable2; echo "
"; echo $variable3; echo '
'; echo $variable4; ?>
Perform the same steps as above to run.
90 String c 98.05
In PHP there are no primitives like in java. Every variable starts with $ sign and can hold any type of value the PHP handles it implicitly to find out the type of value the variable is holding and by default it is considered as a string.