Tutorial What is PHP?

Malcolm

Administrator
Administrator
Jan 2, 2018
828
204
55
Canada
codeforum.org
What is PHP?

Just like HTML, CSS and JavaScript. PHP has its purpose as well. In this What is topic I’ll go over what PHP and its file extensions are, what its purpose is and some examples of PHP in use.

PHP is a Hypertext Preprocessor scripting language that is used to make websites more interactive and dynamic. Unlike HTML, CSS and JS, PHP is a server-side scripting language or a backend scripting language. You can identify PHP files by looking for the .php extension; however, you may also see PHP being embedded within a .html document. You can spot PHP in an HTML document by looking for the similar syntax below: (<?php and ?>) between the <body></body> tags, PHP statements usually end with a semicolon (;).

PHP:
<?php
echo "My first PHP script!";
?>
PHP can be used to have a login/registration system. It can create, open, read, write, delete, and close files on a server. PHP can also be used to collect data, add, delete and modify a database and can also be used to encrypt data. You can view more here: https://www.w3schools.com/php7/php7_intro.asp

Here are some examples of PHP in action:

Example(s) from w3schools:
PHP:
<?php
echo "Hello World!";
?>
PHP:
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
Of course, please correct me if I am wrong.

Sources:
https://simple.m.wikipedia.org/wiki/PHP
https://www.quora.com/Why-is-PHP-a-secure-server-side-scripting-language
https://developer.mozilla.org/en-US/docs/Glossary/PHP
https://www.w3schools.com/php7/default.asp
 
Last edited:

Ghost

Active Coder
Moderator
Apr 19, 2019
234
94
28
Going off of what you shared, here is some basic math in PHP.
PHP:
<?php
$x = 5;
$y = 10.5;
$addition = $x + y;
echo "$x + $y = $addition"; // shows: 5 + 10.5 = 15.5

$multiplication = $x * y;
echo "$x * $y = $multiplication"; // shows: 5 * 10.5 = 52.5

$division = $y / $x;
echo "$y / $x = $division"; // shows: 10.5 / 5 = 2.1

$subtract = $y - $x;
echo "$y - $x = $division"; // shows: 10.5 - 5 = 5.5

$remainder = $y % x;
echo "Remainder of $y / $x = $remainder"; // shows: Remainder of 10.5 / 5 = 0.5
?>
As you can see, once you declare some numbers with variables you can perform math quite easily using the same symbols you can use with other languages and/or calculators, etc.

Obviously there are other math functions in PHP as well.
For example, you can use the pi() function to return a fairly accurate value. You can mess with your server set up to increase or decrease the precision of pi.

PHP:
<?php
echo pi(); // shows: 3.14.... etc
$x = 3;
$math = $x * pi();
echo $math; // shows the result of 3 * 3.14...
?>
I hope this helps some of you learn some math with PHP and have a better understanding of the possibilities of this language :)[/CODE]