Introduction to PHP
PHP (Hypertext Preprocessor) is a widely-used, open-source scripting language especially
suited for web development. It was originally created in 1994 by Rasmus Lerdorf and has
since evolved into a powerful server-side language.
1. What is PHP?
PHP is a server-side scripting language designed for web development. It's used to create
dynamic websites or static websites or web applications, where the content can change
depending on user input, databases, or other factors.
PHP stand for (Hypertext Pre-processor) that earlier stood for Personal Home Pages.
• Server-side: PHP code runs on the server, and the result is sent back to the user's
web browser as HTML.
• Free and open-source: PHP is completely free to use and has a large community
supporting it.
2. How to Start with PHP
❖ PHP runs on different platforms ( Windows, Linux, MacOS, Unix etc)
❖ PHP is compatible with almost all severs used today
❖ PHP is easy to learn and runs efficiently on the sever side.
• XAMPP (Windows, Linux, macOS)
• MAMP (macOS, Windows)
• WAMP (Windows)
• LAMP ( Linux)
NOUH ABDIRAHMAN 1
Once installed, you can run PHP code by saving it in a .php file and opening it via your local
server (e.g., http://localhost/).
Creating Your First PHP File
Once you've installed XAMPP/WAMP:
1. Go to the htdocs folder (in XAMPP) or WAMP web root folder.
2. Create a file called index.php.
3. Open it in a text editor and add the following:
4. Save the file, and go to your browser. Visit http://localhost/index.php to see your
output: Hello, World!
NOUH ABDIRAHMAN 2
3. Basic PHP Syntax
The default PHP file extension is “.php”
A PHP file normally contains HTML tags , and some PHP scripting code
1. PHP scripts are enclosed within <?php and ?> tags.
<?php
// PHP code goes here
?>
- Echo Statement:
The echo statement is used to output data to the browser. Example
<?php
echo "Hello, World!";
?>
Output: Hello, World!
4. PHP Case Sensitivity
In PHP keyword(e.g. if,else,while,echo, etc) classes, functions, and user-defined functions
are not case sensitive.
In the example below, all three echo statements below are equal and legal
echo"Hello wor";
Echo"Hello word";
ECHO"HELLO WORD";
5. PHP Comments
A comment in PHP code is a line that is not executed as apart of the program. Its only
purpose is to be read by someone who is looking at code.
Comments can be used to:
Let others understand your code
Remind your self of what you did, most programmers have experienced coming
back to their own work a year or two later and having to re-figure out what they did
Comments can remind you of what you were thinking when you wrote the code
NOUH ABDIRAHMAN 3
Use comments to annotate code.
o Single-line comments: // or #
o Multi-line comments: /* */ Example:
// This is a single-line comment
/* This is a
multi-line comment */
NOUH ABDIRAHMAN 4