Welcome to CodeCrew Infotech

shape shape
Shape Shape Shape Shape
Blog

What is the PHP Programming Language and how to used it

 

What is PHP

PHP stands for PHP: Hypertext Preprocessor. PHP is a server-side scripting language like ASP. It's executed on the server side and often is used to generate the HTML code sent to your browser. it is generally considered an easy programming language to learn and use. It is open source and free to download and use Although PHP only started gaining popularity with Web developers around 1998, it was created by Rasmus Lerdorf way back in 1994.

PHP powers a large portion of the web, which is the language used to make the incredibly popular WordPress blogging and content management system.

Why PHP?

PHP is easy to download and use and its runs on different platforms like Windows, Linux, Unix, etc. it's almost all servers used today like Apache, IIS, etc.

 

What is PHP File

PHP files can contain text, HTML tags, and scripts and its returned to the browser as plain HTML

PHP files have a file extension of ".php", ".php3", or ".phtml".

 

Structure & Syntex of PHP

PHP programs are written using a text editor, such as Notepad or WordPad, just like HTML pages.

This extension signifies to the server that it needs to parse the PHP code before sending the resulting HTML code to the viewer’s Web browser.

The structure of PHP is described below

<?php

………………………

No. of statements goes here

………………………

?>

In the above structure <?php indicates the starting of the PHP Scripts and ?> indicates the ending of the PHP Scripts and in between these two we can place the number of statements or coding used to execute the PHP Script.

 

Example:

<?php

echo “Codecrew Infotech”;

?>

As we have seen in the previous example the PHP Script is started with php tag (<?php) and ends with the (?>) tag.

This PHP Script implements one statement with “echo”.

This indicates “echo” is an output statement in the PHP like printf() in C language and the string “Codecrew Infotech” will be displayed on the webpage

Note one thing in the above example it is terminated with the semicolon (;).

So, in PHP every statement terminates or ends with a semicolon.

 

Comments in PHP

PHP also supports comments like C, C++, and Java Languages.

PHP supports two types of comments

1. Single line

2. Multiline comments

through double slashes “ // “ for one-liners or single-line comments and “/* */” for multi-line comments tags that may extend over several lines of code.

 

Example:-

Single Line comment

<?php

// this is the single-line comment

?>

 

Multiline Comment

<?php

/* this is

 the Multiline

 Comment

*/

?>

 

Variables in PHP.

The variable is simply a container that holds the value and it always starts with a $ sign. Because PHP is loosely typed you do not need to specify what kind of variable it is (like an integer or string) like in some other languages.

 

How Do I Run My PHP Code?

You have to simply write the code in HTML using text editors like notepad or batter and use an IDE like Sublime or Visual Studio Code.

Then if you want to run on the local machine then install the local server like XXAMP or WAMP and store the .php extension file in htdocs folder in XXAMPP and www in the WAMP server

After that start the server and open chrome and write the following code:- localhost/file.php

where file.php is the file that you store in your server.