Do You Know These PHP Basics Before Starting Programming
Before you start with PHP, you should know these few things about PHP.
PHP is a Server Side Programming Language, that means PHP code will only be executed on the server and only HTML will be rendered to the browser.
To use PHP Programming Language, you should install PHP based server like LAMP stack. LAMP stands for
L: Linux (In Windows it’s WAMP, In Mac it’s MAMP)
If you are using Windows, you can setup PHP server with WAMP or XAMPP. In mac, you can setup PHP server with MAMP or XAMPP.
Other Articles in PHP Basics Section
- Creating a PHP File with PHP info
- Displaying Text with PHP
- Comments with PHP
- PHP Configuration File
- PHP Error Reporting
Quickly Navigate to Other Sections in PHP Tutorials
For Processing PHP code, you should always use PHP file. That means PHP code should be added to the files with file extension as .php.
Creating PHP File & Adding PHP Code
In this step, we will see creating a PHP File & adding your first PHP code.
Create a new file and save it with .php extension inside www directory or htdocs directory respectively if you are using WAMP or XAMPP.
You can save this file with name as basic.php
In this file add opening PHP tag
<?php, after adding opening PHP tag you can start writing the PHP code.
We can add PHP code till closing PHP tag
White spaces don’t matter inside PHP code, that means you can have as many white spaces.
Every statement should end with a semicolon if you are writing multiple statements this is mandatory.
You can use this PHP code inside HTML also if that file is of PHP extension.
Here is the code that you can reuse
//opening php block
// white spaces don't matter
//Every statement should end with a semicolon
//use the php code in HTML file
//closing php block
In this step, we will see how to use phpinfo Function and adding first PHP statement. In the previous step, we have created a PHP file and added opening & closing PHP tag.
Here we will add single line statement, just add this below line
After adding the above code, load the file in the browser. You should see all the configuration information of your PHP server.
Remember: Don’t use this PHP function on your server, it’s a security risk. Anyone who is having access to this file will easily know the configuration of your server.
If you add this code in HTML file, you won’t be able to see the PHP configuration.
<title>Basics of PHP</title>
PHP won't be processed in HTML file, should use PHP file for adding PHP code.
<?php phpinfo(); ?>
You can learn more about this configuration in the video.