Articles @ Enterrom.com

divider
All the web knowledges related articles that might be feeding your brain.

Understanding PHP, Its Basic Functions and Syntax

Posted on:

Understanding PHP

PHP (PHP: Hypertext Preprocessor) is an open source server side scripting programming language.

As a scripting language, PHP executes programming instructions at runtime. The results of the instructions will of course be different depending on the data processed.

PHP is a server-side programming language, so scripts from PHP will be processed on the server. Server types that are often used in conjunction with PHP include Apache, Nginx, and LiteSpeed.

In addition, PHP is also an open source programming language. Users are free to modify and develop according to their needs. Of course, if you have good coding skills, right?

Why Use PHP?

Currently, no less than 78% of websites worldwide use the programming language created by Rasmus Lerdorf in 1995. Even big platforms like Facebook are using it. So, what makes PHP so popular? Why use PHP which is more than two decades old? Here are some reasons:

  • Tends to be easy to learn — compared to some other popular programming languages, PHP is easier to learn.
  • Abundant learning materials — PHP's "quite old" age causes a lot of documentation, guides, and active communities to be scattered in cyberspace. So, no need to be afraid if you experience difficulties.
  • PHP is open-source — anyone can use PHP without spending a penny.
  • High speed — PHP is proven to increase loading speed compared to other languages. For example, it is three times faster than Python in some cases.
  • Large selection of databases — PHP works with almost any type of database. Starting from MySQL, to non-relational databases like Redis.
  • Good compatibility with HTML — PHP scripts don't interfere with HTML at all. In fact, they both complement each other.
  • High flexibility — PHP can be combined with many other programming languages. So you can use it as needed.
  • Multi-platform — PHP can be used on a variety of operating systems. Starting from Windows, Linux, to MacOS.
  • Always updated — since it first appeared in 1995, PHP is now at version 7.4.
  • Support cloud services — who would have thought, even though PHP is almost two decades old, it can support cloud services with good scalability.

PHP Functions

In general, PHP functions are used for website development. Good static websites like news sites don't need a lot of features. Or a dynamic website such as an online store with a myriad of supporting features. However, the use of PHP is not limited to website development. Because of its high flexibility, PHP can also be used to create computer applications though.

PHP Basic Syntax

Each programming language has its own coding rules. Likewise with PHP. The basic syntax opens with <?php and closes with ?>

Here is the explanation of the code:

  • <?php This is a mandatory code to open a PHP program.
  • Echo is a command to display text.
  • "Welcome"; the text to be displayed and written between quotation marks and semicolon.
  • ?> is the code to end PHP and must be used when combined with other programming languages ​​such as HTML.

PHP syntax is case sensitive. So, the use of uppercase or lowercase letters will also affect the output given.

In PHP, you can also write comments as an explanation of the code written. Comments in PHP use // or */ and will not appear as output in the browser.

All PHP code written must be saved with a .php extension file.

PHP Code Example

1. HTML

You can insert PHP code inside HTML using your favorite PHP editor.

2. CSS

When PHP is used in conjunction with CSS, the output rendered has CSS attributes such as different colours and font sizes.

3. JavaScript

When use all 3 languages together, allows you to create interactive elements on your web page.

Share this page
Back to articles list
Loading...