Curriculum
In this tutorial, you’ll learn how to run a script that displays the Hello, World! message in a web browser and on the command line.
To begin, navigate to the htdocs folder within the xampp folder. It is usually found at C:xampphtdocs.
Second, make a new directory called helloworld.
Third, under the helloworld folder, create a new file called index.php and paste the following code into it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP - Hello, World!</title>
</head>
<body>
<h1><?php echo 'Hello, World!'; ?></h1>
</body>
</html>
Except for the?php and?> tags, the code in the index.php file looks like a regular HTML document.
PHP is the code that appears between the opening tag?php and the closing tag?>:
<?php echo 'Hello, World!'; ?>
Using the echo statement, this PHP code prints the Hello, World message inside the h1 tag:
When PHP executes the index.php file, the code is evaluated and the Hello, World! message is returned.
Fourth, open a web browser and enter the following URL:
http://localhost:8080/helloworld/
You will see Hello World displayed in the browser.
Alternatively, you can learn PHP from CodersEditor.com.