-
Hajipur, Bihar, 844101
PHP stands for Hypertext Preprocessor. It is a server-side scripting language used primarily for web development, but it can also be used as a general-purpose programming language.
PHP code runs on the server, and the result is sent to the browser as plain HTML.
Easy to learn and use
Runs on all major platforms (Windows, Linux, macOS)
Compatible with all major databases (MySQL, PostgreSQL, etc.)
Used in popular platforms like WordPress, Drupal, Magento
Open-source and well-supported by the community
✅ Generate dynamic page content
✅ Handle form data
✅ Create, open, read, write, delete files on the server
✅ Send and receive cookies
✅ Connect to databases
✅ Manage user sessions
✅ Encrypt data
<?php
echo "Hello, World!";
?>
PHP code is enclosed in <?php ... ?>
tags
echo
is used to output text
Statements end with a semicolon ;
Client requests a PHP file (e.g., index.php
)
Web server (e.g., Apache) processes the PHP code
The server sends the output (usually HTML) to the client’s browser
File extension: .php
Can contain HTML + PHP code
Example:
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello from PHP!";
?>
</body>
</html>
Q1. Write a PHP program to display your name.
Example Output:My name is John.
Q2. Write a PHP program to add two numbers and display the result.
Example Output:Sum: 15
Q3. Write a PHP program that uses variables to store a name and concatenate it with a welcome message.
Example Output:Welcome, Alice
Q4. Write a PHP program to check if a person is eligible to vote using an if-else condition.
Condition: Age should be 18 or above.
Example Output:Adult
Q5. Write a PHP program to store colors in an array and display them one by one using a foreach loop.
Example Output:
Red
Green
Blue
Q1: What does PHP stand for?
Q2: Which tag is used to start PHP code?
Q3: Which function is used to output in PHP?
Q4: Which of the following is used to get data from a form?
Q5: Which of the following variables is valid in PHP?