In the previous post, we have been created an environment for php.Now we can develop and test our php scripts on our Personal Computer so, Lets start with a Hello World PHP Script.
Now, I'll tell you about php syntax.To start your php script, we always use these starting and ending tags so, the server will execute the file as PHP Script.
<?php
?>
These two tags are required to execute your code in your web server otherwise it will display as text plain in the browser.
Now, lets create a new Hello World script.
Please follow these steps::
Step 1: Open
PHP Designer 8 and create a new PHP File
when you will click on new php file, php designer will automatically add php tags into the file so, you need not worry about php tags.
Step 2: Write this code into the file
<?php echo"Hello World"; ?>
Here
echo is a php syntax which is used to display a message on the screen.In php programming, every line must be separated by a semi-colon otherwise it may cause errors while executing the script.
Step 3: Save the file into the
Document Root (Default: C:\xampp\htdocs\) and write the name
helloworld.php
Now, its time to test your php code in the browser.Lets check it
Open your Browser and navigate to
http://localhost/helloworld.php
when the page will be loaded, you see the output like this:
Congratulations! You have successfully developed your first php script!