What is PHP?
PHP stands for Hypertext Preprocessor and is a programming language primarily used for building dynamic websites. It is open source and free to use. For example, CMSs like WordPress are built on PHP and are widely used around the world. For more details, see Wikipedia’s PHP page.
Main Features of PHP
- Easily build dynamic websites
PHP allows for flexible dynamic generation of content that is difficult to achieve with static HTML files alone. For detailed information and usage examples, see the official PHP manual. - Open source
Because the source code is publicly available, anyone can use, modify, and redistribute it for free. For the latest information and updates, visit the official PHP website. - Rich frameworks and CMSs
There are many frameworks and CMSs like WordPress and Laravel, which contribute to increased productivity. The official Laravel website features the latest use cases and feature introductions.
How PHP Works
- A request is sent from the browser to the server
- The server loads the specified .php file and the PHP engine executes the code
- The server sends the generated HTML, JSON, etc., as a response to the browser
- Only the final output is displayed in the browser
PHP is a scripting language that runs on web servers. This section explains step by step how PHP receives requests, processes them, and returns results.
1. A request is sent from the browser to the server
- User action
When a user enters a URL in the web browser, clicks a link, or fills out and submits a form, a request is sent to the server. - Request contents
The request includes information such as which file is being requested and what data is being sent.
2. The server loads the specified .php file and the PHP engine executes the code
- Role of .php file
The server confirms that the requested file is a PHP file (with a .php extension) and delegates processing to the PHP engine. - PHP engine
The PHP engine reads the code in the file line by line and executes the instructions. This includes operations like retrieving data from a database or performing calculations. - Executing code
PHP code is written within<?php ... ?>
tags and is executed to dynamically generate data.
3. The server sends the generated HTML, JSON, etc., as a response to the browser
- Generating output
The PHP engine generates data such as HTML, JSON, or XML as a result of executing the code.
Example: Dynamically generated web pages or API responses. - Sending process
The generated output is sent from the server to the browser as an HTTP response.
The browser receives the response and interprets the content to display it on the screen.
4. Only the Final Output is Displayed in the Browser
- What the user sees
What the user actually sees in the browser is only the final output generated after the PHP code has been executed.
For example, a web page with applied HTML and styling, or an API response. - Source code not exposed
Since PHP is processed server-side, the actual PHP code (the program’s source code) is not sent to the user.
This means users cannot directly view the code, which is a security benefit.
Security Benefits
- Code protection
PHP code is executed on the server, and only the final output is sent to the browser.
This reduces the risk of exposing confidential information or server-side logic to the outside. - Dynamic processing per request
Because processing is done dynamically for each user request, users cannot directly access the PHP source code.
How to Write PHP
PHP is a server-side programming language that can be used in combination with HTML. Below, we will explain how to create PHP files and the basics of writing PHP.
File Extension
Files created with PHP must be saved with the .php extension.
For example:
- test.php
- index.php
Example: Saving to a Windows folder

These are common file names.
Why is the file extension important?
- Server recognition: The web server determines which programming language to process a file with based on its extension.
- Security and stable operation: Using the correct extension prevents unintended file executions or errors.
Basic Syntax
When writing PHP code, always enclose it within <?php
and ?>
tags.
Write the processing logic and instructions within these tags.
Anything outside of the PHP tags is interpreted as HTML, allowing PHP and HTML to be mixed.
Example: Output “Hello, World!”
The following code uses the basic PHP syntax to display Hello, World! in the browser.
<?php
echo "Hello, World!";
?>
<?php
Indicates the start of PHP code.echo
A command to output strings or variable values to the screen."Hello, World!"
The string to be output.?>
Indicates the end of PHP code.
Output with echo
echo
is the most basic output command in PHP.
It is commonly used to display the result of a program in the browser.
Example of using echo
The following code displays Let’s start PHP! in the browser.
<?php
echo "Let's start PHP!";
?>
Display example in browser

Key Points
- Display strings easily:
echo
can be used in a single line, making it beginner-friendly. - Can output variables and HTML:
echo
can output not only strings, but also variable contents and HTML tags.
Example: Outputting a variable’s value
<?php
$greeting = "Hello, PHP!";
echo $greeting;
?>
Browser display example

In this example, the string “Hello, PHP!” assigned to the $greeting
variable is output.
Using variables allows for reuse of values and dynamic output within the program.
Types and Usage of Comments
In PHP, comments are used to improve code readability and make it easier to understand when revisiting later. Comments do not affect the program’s operation and serve as notes or supplementary explanations for developers.
1. Single-line Comments
Single-line comments are used to write comments on a single line. There are two ways to write them:
① Using //
This is C++-style commenting and can be written at the beginning of a line or next to code.
<?php
// This is a single-line comment
echo "Hello, World!"; // This is also a comment
?>
② Using #
This style is inspired by shell scripts or Perl, but it’s also available in PHP.
<?php
# This is a single-line comment
echo "PHP is convenient"; # This is also a comment
?>
2. Multi-line Comments
Multi-line comments are used when writing comments over multiple lines.
Start with /*
and end with */
.
<?php
/*
This code receives user input
and saves it to the database.
*/
$user_name = "Taro";
echo "Hello, " . $user_name . "!";
?>
They can also be used to temporarily disable code during debugging.
<?php
/*
echo "This code will not be executed";
echo "Disabled because it’s commented out";
*/
echo "This is active code";
?>
3. Documentation Comments (PHPDoc)
In PHP, PHPDoc comments are used to describe functions and classes in detail.
They are useful when combined with IDEs (Integrated Development Environments) or documentation generation tools to assist in code completion and explanation display.
① Basic PHPDoc comment
<?php
/**
* Function to get the user's name
*
* @param string $name User's name
* @return string Name with title
*/
function getUserName($name) {
return "Mr./Ms. " . $name;
}
?>
② Description of classes and properties
<?php
/**
* User class
*/
class User {
/**
* User's name
* @var string
*/
private $name;
/**
* Constructor
* @param string $name User's name
*/
public function __construct($name) {
$this->name = $name;
}
/**
* Method to get the name
* @return string User's name
*/
public function getName() {
return $this->name;
}
}
?>
4. Tips for Using Comments Effectively
Explain the intent of the code
Writing why a certain process is needed rather than just what it does results in more valuable comments.
Be mindful of the amount of comments
Too many comments can reduce readability. Avoid unnecessary comments when the code is self-explanatory.
Use PHPDoc effectively
Clear documentation of functions and classes improves maintainability.
Summary
By mastering these basics, you can take your first step into PHP programming. Try writing code and learn while checking how it works.
PHP is a language that is easy for beginners to learn. It has powerful capabilities for building dynamic websites, and many frameworks and CMSs exist to streamline development. Start by learning how to create files and write basic syntax, and try experimenting hands-on to deepen your understanding.