PHP Tutorial
PHP Tutorial
Tutorial
❮ HomeNext ❯
Learn PHP
PHP is a server scripting language, and a powerful tool for making dynamic
and interactive Web pages.
<?php
echo "My first PHP script!";
?>
</body>
</html>
Try it Yourself »
PHP Exercises
Test Yourself With Exercises
Exercise:
Insert the missing part of the code below to output "Hello World".
"Hello World";
PHP Examples
Learn by examples! This tutorial supplements all explanations with clarifying
examples.
My Learning
Track your progress with the free "My Learning" program here at W3Schools.
PHP References
W3Schools' PHP reference contains different categories of all PHP functions,
keywords and constants, along with examples.
PHP References
W3Schools' PHP reference contains different categories of all PHP functions, keywords and
constants, along with examples.
Array Calendar Date Directory Error Exception Filesystem Filter FTP JSON Keywords Libx
ml Mail Math Misc MySQLi Network Output RegEx SimpleXML Stream String Var
Handling XML Parser Zip Timezones
PHP Introduction
❮ PreviousNext ❯
HTML
CSS
JavaScript
If you want to study these subjects first, find the tutorials on our Home page.
What is PHP?
PHP is an acronym for "PHP: Hypertext Preprocessor"
PHP is a widely-used, open source scripting language
PHP scripts are executed on the server
PHP is free to download and use
With PHP you are not limited to output HTML. You can output images or PDF
files. You can also output any text, such as XHTML and XML.
Why PHP?
PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
PHP is compatible with almost all servers used today (Apache, IIS,
etc.)
PHP supports a wide range of databases
PHP is free. Download it from the official PHP resource: www.php.net
PHP is easy to learn and runs efficiently on the server side
❮ PreviousNext ❯
COLOR PICKER
PHP Installation
❮ PreviousNext ❯
What Do I Need?
To start using PHP, you can:
Just create some .php files, place them in your web directory, and the server
will automatically parse them for you.
Run »
<?php
$txt = "PHP";
echo "I love $txt!";
?>
I love PHP!
Try it Yourself »
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.
Below, we have an example of a simple PHP file, with a PHP script that uses
a built-in PHP function "echo" to output the text "Hello World!" on a web
page:
<?php
echo "Hello World!";
?>
</body>
</html>
Try it Yourself »
Note: PHP statements end with a semicolon (;).
ADVERTISEMENT
In the example below, all three echo statements below are equal and legal:
Example
<!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>
</body>
</html>
Try it Yourself »
Note: However; all variable names are case-sensitive!
Look at the example below; only the first statement will display the value of
the $color variable! This is because $color, $COLOR, and $coLOR are treated as
three different variables:
Example
<!DOCTYPE html>
<html>
<body>
<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?>
</body>
</html>
Try it Yourself »
PHP Exercises
Test Yourself With Exercises
Exercise:
Insert the missing part of the code below to output "Hello World".
"Hello World";