PHP | All You Need to Know!
ULTIMATE PHP TUTORIAL!
This is the ultimate tutorial on PHP! From echoes to passwords-it has everything!
Let's get started right away!
PHP is a lot like HTML-really.
PHP is like HTML with PHP codes, more or less.
So really, PHP is just HTML with more stuff!
But... There's something bad about it...
Repl.it only supports PHP in PHP repls. If you create an HTML repl and add a PHP file, this happens:
That's right, folks.
PHP in an HTML repl just shows the code.
BUT, you can make a PHP repl and then add HTML files and, if you want, more PHP files.
IMPORTANT NOTE: Use PHP Web Server for HTML, not PHP CLI.
Ok, let's get started with the basics.
echo is probably the most common php command.
echo writes that specific text to the html document.
IMPORTANT NOTE: Always add
;after each PHP line of code.
PHP Data Types
PHP also has variables, arrays, you know, the usual stuff.
PHP variables start with
$. I don't know why. Maybe the guy who made PHP is obsessed with money. But that doesn't matter right now.
Also, you can add strings:
Here's how you use variables:
Getting the information from arrays:
PHP If, Else, Else If Statements
Here's where it does.
An if statement is like this:
That's so weird...
I added two if statements!
You only added one. Why? Because that one you thought is the second one is also an
else. So, 5 does equal 5. But that's happening. So, since that
elseif technically is an
if and an
else, it can't happen unless the if right next to it doesn't happen.
There's way more operators than the
= sign. Look:
|==||Equal||$x == $y||Returns true if $x is equal to $y|
|===||Identical||$x === $y||Returns true if $x is equal to $y, and they are the same data type|
|!=||Not Equal||$x != $y||Returns true if $x is not equal to $y|
|<>||Not Equal||$x <> $y||Returns true if $x is not equal to $y|
|!==||Not Identical||$x !== $y||Returns true if $x is not identical to $y, or they are not the same data type|
|>||Greater Than||$x > $y||Returns true if $x is greater than $y|
|<||Less Than||$x < $y||Returns true if $x is less than $y|
|>=||Greater than or Equal To||$x >= $y||Returns true if $x is greater than or equal to $y|
|<=||Less than or Equal||$x <= $y||Returns true if $x is less than or equal to $y|
PHP Logical Operators
|and||And||$x and $y||True if both $x and $y are true|
|or||Or||$x or $y||True if either $x or $y is true|
|xor||Xor||$x xor $y||True if either $x or $y is true, but not both|
PHP Variable Changing
Changing variables is quite simple, for example:
BONUS: How to Make a Password!
Just in case you wanted something to get you started, here's a quick little tutorial on how to make a password!
index.php, add this code:
Now, make a new file named
Add the following code:
Lemme back up...
The form is for the form.
$_POST we get the information from the form (as said in my PHP Form Tutorial).
if statement checks if the password is right.
In the sting that says, "your-password-here", you can change that to whatever you want!
Also, you can change what echoes when you get it right and get it wrong.
Well, I told you everything you will ever need to know about PHP. PHP really is an amazing language-
You can make databases,
I can't wait to see what you make with this tutorial, and, like I always say, stay six feet or 20 potatoes or 4 squids apart, wear your masks, wash your hands, practice, be curios, and...
DON'T STOP CODING!