PHP Basic Syntax
Where to Create PHP Files
Double click on this folder and inside it create another folder, you can name it anything you want. Let me name it PHPtest.
Once it’s done, now inside this PHPtest folder you can create your PHP files and save it with an extension of .php.
Now you need to open that PHP file that you have created inside the PHPtest folder on your code editor and start writing a PHP code.
Write Hello World in PHP
PHP scripts always starts with <?php and ends with ?>. These tags are called canonical tags. Between these canonical tags you can write all your PHP code. Here is a Syntax:
<?php // PHP code here...; ?>
To understand it clearly let’s write our first PHP program and print Hello World.
<?php echo "Hello World!"; ?>
You can run this code on any code editor if you have installed PHP extension. In case, if you don’t have installed PHP Extension or your Code Editor doesn’t have any PHP extension you can open the web browser and type
phpFolderName is actually the folder where you have store your php file.
Keep in mind that you must open Apache and MySQL component, before you run your PHP Code. As discussed in our Previous Post.
Comments in PHP
Comments in PHP or in any other programming language are used to provide extra information about the code. It helps other programmers to clearly understand the code. Comments are a sequence of characters that is not executed whenever we run the code and they do not effect the execution of our script. Here is how you can add comments in PHP.
<?php // This is a single line comment. /* This is a multi line comment */ ?>
In PHP, // is used to add single line comment. But if want to add comment that fits more the one line then we must enclose it within /*…*/.
Share This Post!