Hello World Program
Before you can create the Hello World program in PHP, you must be connected to some kind of web server, and a database server. You will then also need a workspace. The easiest thing to do is download "XAMPP" as it has the "Apache" web server and it is free. As for a workspace to write code, I will be using "Sublime Text". It is free and it's a quick download. You will need to go into your XAMPP configuration folder once it is downloaded and connect to 'MySQL' and 'Apache'. Then you will be able to open any file by typing in the URL "localhost/insertFileNameHere. The process to get up and running with PHP can seem a little complicated at first so feel free to comment with questions.
The hello world program in PHP is very simple. The syntax looks like this:
<?php
echo "hello world";
?>
The program must open with PHP tags, much like a program in HTML would be embedded in <html> </html> tags. It is also easy to write PHP code within an HTML framework, and when the code is displayed in the browser, it will be embedded in HTML, with the information returned from the PHP code. the PHP "hello world" program embedded in HTML code would look like this:
<html>
<head>
<title>PHP Intro</title>
</head>
<body>
<h1> <?php echo 'hello world'; ?></h1>
<head>
<title>PHP Intro</title>
</head>
<body>
<h1> <?php echo 'hello world'; ?></h1>
</body>
</html>
</html>
Notice the HTML tags. This might not seem very useful just yet, but it becomes useful when creating dynamic websites with large databases, and makes the language easy to integrate in a lot of applications.
Comments
Post a Comment