Horje
PHP Hello World

Whenever we start to learn any programming language, we often begin by writing or printing “Hello World”. In this article, we will see how to print “Hello World” using PHP. To print “Hello World” on the screen using PHP.

There are two most common methods for printing “Hello World” messages which are as follows:

Using the PHP CLI Method

The PHP CLI method allows you to run PHP scripts directly from the command line. This approach is useful for testing simple scripts, running maintenance tasks, or performing operations without the need for a web server.

Example: To demonstrate printing a simple “Hello World” message using the PHP.

PHP
<?php
    echo "Hello, World!";
?>

Output
Hello, World!

Using PHP server method

The PHP server method involves running PHP scripts through a web server, such as Apache or Nginx, which processes the PHP code and sends the output to the browser. This method is commonly used for developing and testing web applications.

Step 1: Install XAMPP or any other PHP server package.

Step 2: Create a PHP File: Create a file named index.php and add the following content:

PHP
<!-- index.php -->
<html>
      <head>
    <title>PHP Test</title>
      </head>

<body>
    <?php echo '<p>Hello World</p>'; ?> 
</body>

</html>

Step 3: Place the File in the Web Root Directory: Move the index.php file to the web root directory of your server. For XAMPP , this is typically

C:\xampp\htdocs

Step 4: Start the Server: Open a terminal and start the XAMPP server:

sudo /opt/lampp/lampp start

Step 5: Access the File in a Browser: Open your web browser and navigate to

http://localhost/index.php

Output:

PHP-Hello-World

PHP Hello World




Reffered: https://www.geeksforgeeks.org


PHP

Related
How to Convert a Given Number to Words in PHP? How to Convert a Given Number to Words in PHP?
Remove Falsy Values from an Array in PHP Remove Falsy Values from an Array in PHP
How to Create a Database Table in Magento? How to Create a Database Table in Magento?
How to Check an Array Contains only Unique Values in PHP? How to Check an Array Contains only Unique Values in PHP?
How to Convert Integer array to String array using PHP? How to Convert Integer array to String array using PHP?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
23