PHP stands for PHP: Hypertext Preprocessor. PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.
PHP files have the extension .php. Only very, very few web hosts do not support PHP, even most Windows hosts support it!
We enclose PHP code inside these tags:
| <?PHP ?> |
Remember this for later, ok?
We use variables to hold information.
We can set variables like this:
| $variable_name = 'Will has so much gay love for Dan.'; |
We can then use them later within another variable or a function. A function does pretty much what it says on the tin.
Let's use the most basic function, echo.
| echo "Hello Avengex Users!"; |
This will output: Hello Avengex Users!
You can also echo variables like this...
| $lovers = 'Dan and Will forever.'; echo $lovers; |
...or use them like this:
| $who = 'Avengex Users!'; echo "Hello $who"; |
As you have probably noticed by now, each time you set a variable or use a function, you must end that line with a semi-colon. (;)
Next, let's do some simple calculations.
We use these basic mathematical operators:
+ for addition.
- for subtraction.
* for multiplication.
/ for division.
Let's try it:
| $sum = 1 + 1; echo $sum; |
Fancy going a bit more advanced?
| $sum = 5 * 42 + 10; echo $sum; |
What to do? Use an if/else statement!
We can use if/else statements to make decisions in PHP, and do certain things depending on the answer.
Here's an example:
| $weather = "sunny"; if($weather == "sunny"){ echo "Looks like it's going to be a nice day today!"; } else { echo "It's not going to be sunny today!"; } |
PHP checks to see if what is contained inside the brackets is correct/true. If it is, it executes what's inside the first set of curly braces. If it is wrong/false, it skips to the else part, and executes what is inside the latter curly braces.
Full example.
Just to show you what it looks like when it's all pieced together.
| <?PHP $maths = "fun"; if($maths == "fun"){ $sum = 4156 + 5498; echo "4156 and 5498 added together equals $sum!"; } else { echo "Maths sucks."; } ?> |
Kthxbye.
Hope you learnt something from this random waffle. I'm going to go indulge myself in chocolate now. Thanks for reading and let me know what you think, any improvements or suggestions?
Feel free to PM me or email me if you have any questions, and don't forget to check out the PHP site at www.php.net for lots of info.
Related Articles
- PHP IntroductionA short and simple introduction to
- Introduction to SerializingAlso includes an example that you can use to start building apps with serialize.
- Introduction to Procedural ProgrammingWell start of with if
Here is the basic usage of it
variable would be something like $variable - Introduction to FTPFTP stands for File Transfer Protocol and is a standard application protocol that uses the Internet
- What IS A Blog?People maintained blogs long before the term was coined, but the trend gained momentum with the introduction of automated published systems, most notably Blogger at blogger.com...
- The Beginner's Introduction to SEOHere is a question for you: Would you rather have a really artistic and beautifully designed website or an ugly and very plain looking one? Well obviously you would naturally pick the pretty one right? However, here is a second question: Would you rather show up on the first page of major search eng...
- Introduction to Graphic DesignIf you are going to go into practically any form of business, graphic design is something you are going to become familiar with quickly. Here is a primer.
- Introduction To CookiesCookies : A collection of information, usually including a username and the current date and time, stored on the local computer of a person using the World Wide Web, used chiefly by websites to identify users who have previously registered or visited the site.
- Introduction to InductionInduction familiarizes the new recruits to the organization functioning so that they become productive in the least possible time; they are a means of honing the workforce to greater efficiency, precision, and perfection.
- Flash Intros On Websites - Why It's Time To Ditch The Flash IntroThe designer who wrote this article makes some very good points about Flash Intros. After he explains the pros and cons of Flash Intros he gives great advice in deciding for yourself, with new understanding.
