PHP Introduction – What is PHP – Hello world script in PHP

In this tutorial, I am going to start a tutorial on the most popular web development language that is PHP. It is a widely used scripting language that is used to make the webpage dynamic. Tutorials begin from PHP introduction.

This tutorial series will be very helpful for beginners and professionals both. I will share all topics related to PHP such as variable, array, object-oriented, string, file-handling, regular expression, etc. in one by one tutorial series.

PHP introduction. What is PHP?

PHP is a scripting language that is used to serve dynamic webpages. It requires the server to execute code. Therefore, it is called a server-side scripting language. It is best suitable for web development. Therefore, it is used to develop a web application executed on the server and serve dynamic webpages.

What do you mean by scripting language? The scripting language is also a part of programming language but it doesn’t require compilation steps. It is only interpreted by an interpreter where source code is directly converted to machine code at the time of program execution.

PHP was earlier known as “Personal Home Page“. Later, it was renamed as “Hypertext Preprocessor“. It is a widely used open-source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

What does open-source mean? Open-source means the software code available for free to use or modify so that anyone can modify and fixes the bug on that software but it is licensed under Open Source Initiatives. For example, think about a free park where every person can visit freely and plant some trees according to their choice for a better environment.

It was created by Rasmus Lerdorf in 1994 but first appeared in 1995.

Why should we use PHP?

Most peoples arise questions on it that why should we use PHP because there are so many languages already available in the market then why we choose PHP to develop web applications?

We choose PHP for the following reasons:

  • It is an open-source scripting language and it is free to use.
  • It is faster than other scripting languages. For example, JSP (Java Server Page), ASP(Active Server Page).
  • It is very easy to learn because its syntax is too clear.
  • There are so many documents freely available on the internet related to PHP projects because it is free.
  • Most of the web hosting server supports PHP by default while ASP and JSP are not supportable in all servers yet.
  • Most of the tutorials freely available on the internet to learn PHP easily.
  • It is supported by all operating systems such as Linux, macOS, Windows, etc.
  • It supports most of the available databases such as MySQL, PostgreSQL, Oracle, ODBC, Mongo-Db, etc.
  • It is updated regularly according to the latest technology so that we can develop applications according to the latest technology.

What we need to execute PHP code?

Most of the peoples write PHP code in a local computer for learning purpose and development purpose. To write and execute PHP on the local computer, you need an Apache server to execute PHP code because it is a server-side scripting language that runs on the server.

To execute PHP script, you must have following software and tools:

  • PHP Parser: it is a tool that converts source code (human-readable code) to machine code (computer-readable code).
  • Web server: As I already mentioned that PHP is a server-side scripting language. Therefore, it requires a server to execute code. PHP is generally executed on Apache or Nginx web server, but nowadays, it is also executed on the IIS server after some configuration.
  • Web Browser: As we all know that a web browser is required to open a web application. To see the output of the PHP code, we need a web browser that displays HTML code and PHP code output.

PHP Hello World Program

Let’s see a simple string printing program in PHP. Here, I am going to write a simple program that will print “Hello World” on the output screen.

<?php 
echo "Hello Word";
?>

This program is a pure PHP program because it doesn’t contain any HTML tags. In this program, I have written PHP syntax first. and then written an echo statement that helps to print output on the screen. And lastly, PHP syntax closed.

PHP syntax starts with less than and a question mark symbol followed by PHP (<?php) and ends with a question mark and greater than symbol (?>). It is not case sensitive, you can write it in the lower case and upper case both but it is highly recommended to write in the lower case.

Variable names are case sensitive that means if you declare a variable in a lower case $number = 40; then you can’t use it in upper case such as $NUMBER. Here, $number and $NUMBER both are different variables.

Function names are not case sensitive that means if you create a function with the name test() in lower case then you can also call it in upper case such as TEST().

Semicolons (:) are mandatory to break a line of the statement. If you write only one statement inside PHP syntax then semicolon is not mandatory but if you write multiple lines of codes in a single PHP syntax then you have to write semicolon to end line of the statement.

For example:

<?php
echo "PHPTREEPOINT"
?>

The above code is correct because it has only one line inside a PHP syntax. It will print PHPTREEPOINT on the screen.


<?php
echo "PHPTREEPOINT"
echo "Tutorial"
?>

The above program is incorrect. It gives syntax error because there is more than one line inside a PHP syntax. Therefore, a semicolon must be to break each line.

Hello World Program with HTML

Many students think about how can we write a PHP program in HTML. Let’s see a Hello world program with HTML in PHP. As we all know that PHP can be embedded in HTML that’s why we can write PHP code inside HTML but file extension must be (.PHP)

<!DOCTYPE html>
<html>
<head>
	<title>Hello World Program</title>
</head>
<body>
	<h1><?php echo "Hello World!"; ?></h1>
</body>
</html>

What should we learn before?

We can’t make a complete web application only from PHP that’s why we need to learn HTML, CSS and JavaScript before learning PHP.

  • HTML (HyperText Markup Language)
  • CSS (Cascading Style Sheets)
  • JavaScript

What you learn?

I taught you so many things about PHP introduction. Tell me the answer to the following question.

  • Does PHP a programming language or scripting language?
  • Is PHP a case sensitive language?
  • Can we develop a complete web application only in PHP?
  • Can we run PHP code without a server?
  • What PHP stand for?
  • Who created the PHP language?

Read Also:

2 thoughts on “PHP Introduction – What is PHP – Hello world script in PHP

  1. Your way of describing all in this post is really good, every one be able to
    easily understand it, Thanks a lot.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!
iganony