Note: In this site, I am using XAMPP server and in windows operating system and installed XAMPP in C drive, so make sure you install XAMPP server.
- The popular editor used to edit a PHP code
Step by step run PHP program is given below
- Go into HTDOCS folder and create your folder name like "first_program", and into folder create a file give a name "welcome.php"
- "welcome.php" file open in any editor you like.
- Start the XAMPP server and start Apache and MySQL.
- Below code write into "welcome.php".
- PHP script that uses a built-in PHP function "echo" to output.
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World! ";
?>
</body>
</html>
- See output in web browser like Chrome, Microsoft Edge, Internet Explorer, Firefox, etc.
- seacrch localhost/your_folder_name = http://localhost/first_program/welcome.php.
-
In PHP, keywords (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
<!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>
</body>
</html>
Note: In PHP, 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:
<!DOCTYPE html>
<html>
<body>
<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My bike is " . $coLOR . "<br>";
?>
</body>
</html>
Output:
My car color is red
Notice: Undefined variable: COLOR in C:\xampp\htdocs\example\p6.php on line 8
My house color is
Notice: Undefined variable: coLOR in C:\xampp\htdocs\example\p6.php on line 9
My bike color is
Note: In above example,my house is and my bike is name was not show because "Undefined variable : $COLOR, $coLOR"