In this tutorial, I am going to explain how to write your first php web page with programming example for beginners and where to write php code. After setting up your website (by activating your domain on a host server - sign up & subscribe to read more), open any text file editor. You could simply use your notepad program which is already provided in all computer systems; click start on lower left of screen and search for "notepad".
Once opened your text editor, suppose a new empty file is shown, otherwise go to file > new in the top toolbar and write the below lines.
First php program or code example lines
echo "This is my first words to world!";
?>
Explanation of the above php code lines
- "<?php" is the opening expression which informs the server (behind the browser) that you are going to start a php programming or coding block.
- "echo" is one of the php keywords which means display the next text or html, is referred to as a string. It is important to know that any string should start and end with quotes or double quotes, where this will be explained in details in next tutorials.
- ";" is a closing expression which informs the server that this is the end of the command.
- "?>" is the closing expression which informs the server that you are going to end the php programming or coding block, alternating to the above "<?php" expression.
How to save a php coding file & where to write php code
Now, save the file in your main director folder provided by the host and name it as "index.php". The file extension ".php" is important to inform the server to direct this file to the proper translator as to process it back with readable results in the browser. In such case, the php translator is called "Apache" and used by any server. While, file name "index" is the default informing the server that this is the main file to be loaded first without mentioning it in the url (link address or path), as will follow.
What is displayed if missing any of php expressions ?
Not following the above expression orders will end with errors displayed in browser, mainly in the absence of "<?php" opening expression, the above code block will be displayed as it is with being processed.
How to load php file in browser
Open your browser, write in the top url address bar the folder path for example http://localhost/my-site-1/ in case of using a simulation program on your computer like wamp or similar. Note that the previous url exactly matches http://localhost/my-site-1/index.php as referred to before. Then, press enter in order to load the saved file in the browser. Once the file is loaded, suppose it will only show the following string:
References:
- Practical Experience
Related Articles
Latest Articles
- What are Php Arithmetic and Comparison Operators ? | Php Tutorial
- What are Php Variables and Types ? | Php Tutorial
- How to write your first php web page with code example | Php Tutorial
- Introduction to Php Learning Course | Php Tutorial
- How to Secure your JavaScript Code from being Copied by Competitors | Javascript Tutorial
- How to Promote JavaScript To Speed Your Website Loading Time For Higher SEO Performance | Javascript Tutorial