PHP | All You Need to Know!
Whacko

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.

The Basics

echo is probably the most common php command. echo writes that specific text to the html document.
For example:

IMPORTANT NOTE: Always add ; after each PHP line of code.

Output:

Since the PHP echo tag writes on the html, you can also add html:

Output:

Also, the echo tag does not erase the whole document, so you can add as many echo tags as you want.

Output:

Super cool, right?

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.
Variable example:

Also, you can add strings:

Here's how you use variables:

Output:

Using commas joins text or number together.
Also, there is arrays.
Example of an array:

Getting the information from arrays:

Output:

And, changing the data from the array:

Output:

PHP If, Else, Else If Statements

Now, sometimes PHP can be a lot like JavaScript.
Here's where it does.
An if statement is like this:

If 5 is equal to 7, it will echo "5 is equal to 7!".
But, if it is not, than it will echo "5 is not equal to 7!".
And we all know 7 is not equal to 5, so we should get this:

Also, there is elseif:

Output:

The reason is because the elseif echoes "5 is not equal to 4, but it is equal to 5!" if 5 is not equal to 4, but is equal to 5.
But let's say we changed that code to this...

And we will get only one "5 = 5":

You're probably thinking:

That's so weird...
I added two if statements!

WRONG!
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:

OperatorNameExampleResult
==Equal$x == $yReturns true if $x is equal to $y
===Identical$x === $yReturns true if $x is equal to $y, and they are the same data type
!=Not Equal$x != $yReturns true if $x is not equal to $y
<>Not Equal$x <> $yReturns true if $x is not equal to $y
!==Not Identical$x !== $yReturns true if $x is not identical to $y, or they are not the same data type
>Greater Than$x > $yReturns true if $x is greater than $y
<Less Than$x < $yReturns true if $x is less than $y
>=Greater than or Equal To$x >= $yReturns true if $x is greater than or equal to $y
<=Less than or Equal$x <= $yReturns true if $x is less than or equal to $y

PHP Logical Operators

OperatorNameExampleResult
andAnd$x and $yTrue if both $x and $y are true
orOr$x or $yTrue if either $x or $y is true
xorXor$x xor $yTrue if either $x or $y is true, but not both
From PHP Operators (W3schools.com).

PHP Variable Changing

Changing variables is quite simple, for example:

+= adds the number to the number next to it.
Output:

Also, there are these:

  • -=: Subtraction
  • *=: Multiplication
  • /=: Division
  • %=: Modulus

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!

  1. In index.php, add this code:

Now, make a new file named result.php.
Add the following code:

Lemme back up...
The form is for the form.
Using $_POST we get the information from the form (as said in my PHP Form Tutorial).
And the 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,
forms,
quizzes,
and more!
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!

Any issues with this tutorial? Any ; I forgot? Please comment so I can update this tutorial. Feel free to post things you make with this tutorial in the comments.
Good websites for practice include:
-W3schools.com
-TutorialRepublic.com
-Repl.it
You are viewing a single comment. View All
Bookie0

np! :) @Whacko