Post: [GUIDE] PHP for newfags (non-sp00nfeed)
03-29-2011, 03:11 PM #1
vSaBoTeuR x
< ^ > < ^ >
(adsbygoogle = window.adsbygoogle || []).push({});
PHP: Hypertext Processor


Welcome to this series of tutorials for PHP! These tutorials will be written by me, but will sometimes include codes of other programmers. When I do that, I will - of course - leave a source. If you have suggetions, corrections or have a tutorial you've written about the fine fundamentals of PHP, don't hesitate to PM them to me. You must login or register to view this content. Is something unclear for you? Post a message in this thread and I'll try to explain it for you.

Now you know that, we can go on to the next step: Getting Started.

[multipage=Getting Started]

PHP: Hypertext Processor
Getting Started


To start using PHP, you will need a few things. Here's a list of what you will need.


  • Hosting with PHP5+
  • Notepad (Microsoft Word = AIDS)
  • A brain
  • Concentration


1. Hosting with PHP5+
I can't stress this enough. If you don't have (hosting with) PHP, you can't proceed. If you think you can proceed. Please take a gun and shoot yourself.

2. Notepad
I recommend You must login or register to view this content. for this. You may need to get used to it, but you'll enjoy it when you've mastered it.
For Mac OSX users, I recommend Smultron. You have to search it yourself, sorry.

3. Basic knowledge of HTML4.1+
This will come in handy, as I will use HTML as layout for our applications. I will not use CSS for layout. It is about PHP, not web designing!

4. A brain
Unlike Visual Basic, object-orientated programming languages like C++ and even PHP require a brain!

5. Concentration
Concentration is required (unlike Visual Basic). However, if you are diagnosed with disorders like ADHD, I think you can proceed anyway. Just make sure it isn't a critical version of ADHD.
this is not intended to discriminate people with ADHD

So you have that all? Let's get to write the first things!

[multipage=Your First App]

PHP: Hypertext Processor
Your First App


Let's make our first application. It's going to be very basic, so you should be able to follow right away.

When using HTML to say something basic like "Hello World!" You would use something like this.
    
<html>
<head><title>Hello World!</title></head>
<body>
<p>
Hello World!
</p>
</body>
</html>


Let's dynamify that with PHP!
    
<html>
<head><title>Hello World!</title></head>
<body>
<?php

//comments can be made with two slashes and then your comment
echo "Hello World!";

?>
</body>
</html>


This will make it do the same thing as you did with the HTML code we've looked at first. You might ask: "Kroxldyphivc, WTF is that good for?"
Well, it is something to start with! Happy

You start a PHP-script with the following tags.
    Opening tag: <?php
Closing tag: ?>


Back in PHP4 you could open and close tags with <? and ?>. But in the futuristic PHP6, this will be unsupported, rendering your code useless.
The command echo will display text to the screen. It is a special command, due to it not using () for the input, just like in other commands (ex. require("page2.php");). Keep in mind PHP frameworks like VoicePHP will replace this function with a voice.
You can also use print to display your text, but I disrecommend it due to it making the page load slightly longer (1/10 second). Again, the syntax for this function is print "Hello World!";. Basically the same as for echo.
Just like in C++, commands will be closed with a ; (sorry, forgot english name). This will tell PHP it can start executing the next command.

Could you follow? If yes, great! We will continue with variables! If not, it doesn't matter, try reading it again and you'll get it. Don't forget you can always ask your questions to me and I will answer them ASAP.

[multipage=Variables]

PHP: Hypertext Processor
Variables


Variables. Do you know a programming language without them? Well, PHP has variables. Let me explain what they are.

Variables include information. They have names. For example: $age will most likely include information about the user's age. It can include anything as value, from "newfag" to "oldfag", from 13 to 65 (numbers don't need quotation marks, you can just enter the number as value). As you saw, it can be really anything. The information in variables, can later be used in an application. Like maybe age restrictions, etcetera. One of the most used functions for variables is information an user sends through a form to the back-end PHP script.

Important to know!

  • ALL variables will start with a dollarsign ($).
  • Variablenames can have an unlimited long size.
  • Variablenames can only exist out letters, numbers and underscores.
  • Variablenames can only begin with a letter or an underscore. They can never begin with a number.
  • Variablenames can not use spaces. As replacement for spaces, $my var will be $my_var or $myVar.
  • There will be made a difference between capital and normal letters. $var is not the same as $Var.
  • Give variables a clear name. Give them an one-word description about what it will be containing. If you're teaming up with someone to build an webapp, it will not be easy for your partner to understand what you're meaning with variables like $A, $B, $C and/or $D. PHP doesn't get confused by it, but you will get confused by it.
  • Variables can contain ANYTHING. There are no restrictions in the values. The only restrication is; NO QUOTATIONMARKS! The only time you'll be using those are when you will be opening and closing the definition of your variable.
  • PHP variables in general perspective can be defined after you use it. Example: <?php echo $username; $username = "Kroxldyphivc"; This will print Kroxldyphivc to the screen.
  • You don't have to define what data type you're using for your variable.


Let's make an application that stores the name and age of an user inside the script (pre-defined) and make it output it to the screen/webpage.

    <html>
<body>
<?php

$name = "Henk"; //var's with text or text + numbers REQUIRE to be defined using quotation marks!
$age = 16; //numerial var's can be defined without quotation marks. with quotation marks is also allowed.

echo "$name is $age years old."; //output to webpage

?>
</body>
</html>


The output will look like this:

Henk is 16 years old.

When outputting a single variable, you do the following.

    <?php

$variable = "definition";
echo $variable;

?>


The same applies for the command print.

This is currently the last chapter. I am currently busy writing the new chapter, which will be covering string variables.


~Kroxldyphivc
29/03/2011
Last edited by vSaBoTeuR x ; 03-29-2011 at 04:56 PM.

The following user thanked vSaBoTeuR x for this useful post:

Mr Hankey
03-29-2011, 07:43 PM #11
Default Avatar
Oneup
Guest
Originally posted by Kroxldyphivc View Post
Apparently I do, because I else couldn't say the code looks ugly and the syntax is shit.


Actually now you are changing the topic. We are talking about it being OOP, I understand that when you know you are wrong you need to change it up, but at least admit you were wrong and learn something once in a while
03-29-2011, 07:56 PM #12
vSaBoTeuR x
< ^ > < ^ >
Originally posted by UP View Post
Actually now you are changing the topic. We are talking about it being OOP, I understand that when you know you are wrong you need to change it up, but at least admit you were wrong and learn something once in a while


I'm not changing it up. I didn't know it is my fault when you start talking about my VB knowledge being 0%.

If you don't like it, GTFO.
03-30-2011, 07:53 PM #13
I would also recommend the PHP For Dummies Book that can either be downloaded as a PDF file online or bought.
03-31-2011, 05:21 PM #14
vSaBoTeuR x
< ^ > < ^ >
Originally posted by Coder View Post
I would also recommend the PHP For Dummies Book that can either be downloaded as a PDF file online or bought.


I have that book too! But I have it in Dutch, which is a shitty translation. :(
03-31-2011, 05:27 PM #15
Originally posted by Kroxldyphivc View Post
I have that book too! But I have it in Dutch, which is a shitty translation. :(


Lol Winky Winky You could download it as a TORRENT like what i do Winky Winky
_______________
Looking for someone to verify my PayPal. Pm me if you can
Thanks
03-31-2011, 05:37 PM #16
vSaBoTeuR x
< ^ > < ^ >
Originally posted by Coder View Post
Lol Winky Winky You could download it as a TORRENT like what i do Winky Winky
_______________
Looking for someone to verify my PayPal. Pm me if you can
Thanks


Nah, I'm not really into e-books. I like it when I have my books fysical.
03-31-2011, 06:00 PM #17
vSaBoTeuR x
< ^ > < ^ >
Originally posted by Coder View Post
Ahhh ok mate no prob. You could print it off Winky Winky


Well, it's better than buying those goddamn 60 euros books from 1988 on programming Assembly!
03-31-2011, 07:35 PM #18
Default Avatar
Oneup
Guest
Originally posted by Kroxldyphivc View Post
I'm not changing it up. I didn't know it is my fault when you start talking about my VB knowledge being 0%.

If you don't like it, GTFO.


IF you don't know it, dont bash it, this is kindergarten stuff here kid.

It is your fault for providing information that is false, at least write a tutorial and know what you are talking about
03-31-2011, 07:40 PM #19
vSaBoTeuR x
< ^ > < ^ >
Originally posted by UP View Post
IF you don't know it, dont bash it, this is kindergarten stuff here kid.

It is your fault for providing information that is false, at least write a tutorial and know what you are talking about


You must login or register to view this content.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo