PHP (Hypertext Preprocessor) is a server-side scripting language mainly used for web development.
PHP is used to create dynamic web pages and works well with HTML and databases.
PHP code is written inside <?php ... ?> tags.
<?php
echo "Hello, World!";
?>
Variables in PHP start with the $ symbol.
<?php
$name = "Alice";
$age = 20;
echo $name;
echo $age;
?>
PHP commonly uses forms to take input.
<form method="post">
Name: <input type="text" name="username">
<input type="submit">
</form>
<?php
echo $_POST["username"];
?>
<?php
$marks = 75;
if ($marks >= 50) {
echo "Pass";
} else {
echo "Fail";
}
?>
<?php
for ($i = 1; $i <= 5; $i++) {
echo $i;
}
?>
<?php
function add($a, $b) {
return $a + $b;
}
echo add(5, 3);
?>
<?php
$colors = array("Red", "Green", "Blue");
foreach ($colors as $color) {
echo $color;
}
?>
PHP is commonly used with MySQL databases.