PHP - Syntax
PHP Syntax and Semantics is a set of rules that defines the PHP programming language and how a PHP program can be written and interpreted.
Basic PHP Syntax
A PHP script can be placed anywhere in the document. The default file extension for PHP files is " . php ". A PHP file normally contains HTML tags, and some PHP scripting code.
Run Your First PHP Script
The following is an example about how to run a PHP script. What this program does is show a “Hello World!” text on the screen or webpage.
1. Go to XAMPP server directory
2. I'm using Windows 10, so my root server directory is "C:\xampp\htdocs\".
3. Create a folder and name it as "phpsolvprog"
4. Create a file and name it "index.php"
5. Start code Inside index.php
PHP Index file with Basic syntax practice
Source: solvprog.com
We have to now run our script, first we need to get started with XAMPP Control Panel. Make sure you installed XAMPP server correctly. Under the action option click to start button for Apache and MySQL option. It immediately shows active green signal to give you an idea that it started successfully.
Open New Tab
Run "index.php" by opening a new tab in your browser
Load "index.php"
PHP Index file in web browser with root directory link
Source: solvprog.com
On your browser window, type in url section:
http://localhost/phpsolvprog/index.php
PHP Index file running on localhost server
Source: solvprog.com
Great job, you just run a PHP script! It shows you the result!
PHP Syntax with basic rules to get started
Source: solvprog.com
The default file extension for PHP files is ".php".
A PHP file normally accepts HTML tags, and some PHP scripting code.
we have done an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page.
Remember, any of the programming languages are built to solve problems that exist in our life. So be prepared to have an idea and purpose to learn this programming language.Thanks