TN Online TestSamacheer Kalvi practice

PHP: Hypertext Preprocessor: One Mark Questions, Book Back Answers and Notes

12th Standard · Computer Applications · #4

PHP is a server-side scripting language used to make dynamic web pages. This chapter covers how PHP runs on the server, the three styles of PHP tags, variables and their naming rules, the eight data types, the echo statement, comments, and the arithmetic, assignment, comparison, increment and decrement, logical and string operators.

Study this chapter

Asked in previous board exams

8 questions from this chapter came in 7 past public exams. Open any of them to see the answer and explanation.

  1. March 2026
    What is the extension of PHP file?
    See answer in the solved paper →
  2. March 2025
    Which operator is called "identical" ?
    See answer in the solved paper →
  3. March 2024
    Which statement is used to show the output of a string or other data in the screen in PHP ?
    See answer in the solved paper →
  4. March 2023
    Recent statistics of server side scripting language usage depict that 78.9% of Website are developed by ________ Scripting Language.
    See answer in the solved paper →
  5. May 2022
    What is the default file extension for PHP ?
    See answer in the solved paper →
  6. May 2022
    PHP is a ________ programming language.
    See answer in the solved paper →
  7. Supplementary 2021
    In PHP, Default syntax should start with __________ and end with __________.
    See answer in the solved paper →
  8. March 2020
    In PHP, we can use ________ to comment a single line.
    See answer in the solved paper →

About PHP: Hypertext Preprocessor

Medium ~90 min study

A static web page shows the same content to every visitor. A dynamic page changes: it can greet a user by name, show that user's marks, or list the latest results from a database. PHP was created by Rasmus Lerdorf in 1994 to build pages like these, and it is still widely used for websites.

A website usually uses several technologies together. HTML gives the page its structure, CSS controls how it looks, and JavaScript runs in the browser to make the page respond to clicks. PHP is different because it runs on the web server. The server runs the PHP code and sends only the resulting HTML to the browser, so a visitor never sees your PHP source code.

This chapter gives you the basic grammar of PHP: how to write the tags, how to name variables, what data types exist, how to print output with echo, how to write comments and how each group of operators works. Most exam questions test small details, such as which symbol starts a variable name or what the === operator checks, so read the examples carefully.

What you'll learn

  • Explain how a dynamic web page differs from a static one and where PHP code runs.
  • Write PHP code using the default tags and recognise the other tag styles.
  • Name variables correctly, keeping in mind that variable names are case-sensitive.
  • List the eight PHP data types with an example value for each.
  • Write single-line and multi-line comments.
  • Use arithmetic, comparison, logical and string operators in expressions.

Before you start

  • The structure of an HTML page and common HTML tags.
  • Basic CSS for styling a page.
  • The general idea of a variable from any programming language.

Topics covered in this chapter

Server-Side Execution The web server runs the PHP script and sends only the resulting HTML to the browser, so the PHP code stays on the server.
Static and Dynamic Pages A static page shows the same content to everyone. A dynamic page builds its content when requested, often from a database.
PHP Tag Styles Default tags, short open tags that must be enabled in settings, and the old HTML script embed style.
Variables and Naming Rules Names start with $, followed by a letter or underscore. They are case-sensitive, so $Age and $age are different variables.
Eight Data Types String, integer, float, boolean, array, object, NULL and resource. PHP sets the type from the value assigned.
The echo Statement A language construct that prints strings, variables and expressions to the page. Brackets are optional.
Comments Single-line comments with // or #, and multi-line comments between /* and */. PHP skips them when running the script.
Operators Arithmetic, assignment, comparison, increment and decrement, logical and string operators, including the difference between == and ===.

PHP: Hypertext Preprocessor explained

PHP Basics: Tags, Variables, Data Types and Operators

How PHP works

PHP stands for Hypertext Preprocessor. It is a server-side scripting language, which means the code is run by the web server, not by the browser. When a browser asks for a PHP page, the server runs the script, fetches data from a database if needed, and sends plain HTML back. PHP is free and open source, and it runs on Windows, Linux and macOS. It works with many databases, MySQL being the usual choice. To try PHP on your own computer you need a web server such as Apache with PHP installed, for example through a package like XAMPP.

Syntax and tag styles

PHP code is written between an opening tag and a closing tag, and every statement ends with a semicolon. The textbook gives three tag styles:

  • Default syntax: <?php ... ?>, the standard form that always works.
  • Short open tags: <? ... ?>, which work only when short tags are enabled in the PHP settings.
  • HTML script embed tags: <script language="php"> ... </script>, an old style that newer PHP versions no longer support.

Variables and data types

A variable is a named place in memory that holds a value. In PHP every variable name begins with a dollar sign, as in $total. After the $, the name must start with a letter or an underscore, and may then contain letters, digits and underscores. Variable names are case-sensitive: $mark and $Mark are two different variables. You do not declare a type. PHP decides the type from the value you assign, so it is called a loosely typed language. PHP has eight data types: string, integer, float, boolean, array, object, NULL and resource.

Output and comments

The echo statement prints text, variables or the result of an expression, for example echo "Total: " . $total;. It is a language construct, so brackets are not needed, though they are allowed. Comments are ignored by PHP and are written for people reading the code. A single-line comment starts with // or #. A multi-line comment starts with /* and ends with */.

Operators

Arithmetic operators are +, -, *, / and % (modulus, the remainder: 17 % 5 gives 2). The assignment operator = stores a value, and shortcuts such as += add and store in one step. Comparison operators return true or false: == checks whether values are equal, while === (identical) checks that the values are equal and the data types are the same, so 5 == "5" is true but 5 === "5" is false. Increment and decrement operators ++ and -- add or subtract 1. Logical operators and, or, xor, &&, || and ! combine conditions. The string operator . joins two strings, and .= adds text to the end of an existing string.

Common mistakes to avoid

  • Leaving out the $ before a variable name. Write $name, not name.
  • Forgetting that variable names are case-sensitive. $Total and $total hold separate values.
  • Missing the semicolon at the end of a statement, which causes a parse error.
  • Using = when you mean to compare. = assigns a value; == compares values; === compares both value and type.
  • Putting one /* */ comment inside another. The first */ ends the whole comment and the leftover text causes an error.

Test yourself on these with the practice test, then check the worked reasoning in the solved MCQs.

Frequently asked questions

What is PHP used for?

PHP is used to build dynamic websites. The script runs on the server, reads what the user sent, fetches or stores data in a database and produces an HTML page for that user. Login pages, online forms and result pages are typical uses.

Is PHP case-sensitive?

Partly. Variable names are case-sensitive, so $mark and $MARK are different. Keywords such as echo and if, built-in function names and class names are not case-sensitive. Writing them the same way every time still keeps your code easy to read.

What is the difference between == and === in PHP?

== checks only whether the two values are equal, converting types if needed, so 10 == "10" is true. === is the identical operator. It is true only when the values are equal and both are of the same type, so 10 === "10" is false.

How do I write comments in PHP?

For a single line, start the comment with // or #. For several lines, begin with /* and end with */. PHP ignores everything inside a comment.

Why does my PHP code show up as plain text in the browser?

The file is not being processed by a web server with PHP. This happens if you open the file directly from a folder, or if Apache is not running. Start the server and open the page through an address like http://localhost/ so PHP can run it and send back HTML.

What are the rules for naming a PHP variable?

The name starts with $. The first character after $ must be a letter or an underscore, never a digit. The rest can contain letters, digits and underscores only, with no spaces. $total_1 is valid; $1total is not.

How does PHP work with a database?

When a page is requested, the PHP script connects to the database server, for example MySQL, using built-in functions. It runs a query to read or change records, places the results into HTML and sends the finished page to the browser.

Last updated 15 September 2026

More chapters in Computer Applications

View all
1 Multimedia 2 An Introduction to Adobe PageMaker 3 Introduction to Database Management System 5 Functions and Arrays in PHP 6 Conditional Statements in PHP 7 Loops in PHP 8 Forms and Files 9 Connecting PHP and MYSQL 10 Introduction to Computer Networks 11 Network Examples and Protocols 12 Domain Name System (DNS) 13 Network Cabling 14 Open Source Concepts 15 E-Commerce 16 Electronic Payment Systems 17 E-Commerce Security Systems 18 Electronic Data Interchange (EDI)