Welcome Guest [Log In] [Register]
Welcome to Testing. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
the ultimate pie discussion thread.
Topic Started: Aug 25 2007, 01:09 PM (78 Views)
Nuke
Member Avatar

PHP Basics: #1

Contents

• PHP Introduction
• PHP Syntax
• PHP Variables

PHP Introduction

Before reading this Tutorial, you should have a basic Understanding of HTML and XHTML and some JavaScript knowledge would make it easier.

PHP stands for PHP: Hypertext Preprocessor. PHP is a server side scripting language that is used on many occassions. Although it can't be used on InvisionFree (since IF disallows it), it comes in handy when making websites, uploading sites, etc. Some examples of PHP in action, is InvisionFree. The source coding is mainly PHP with a bit of Javascript and HTML here and there. I am currently learning PHP because I think it is more interesting than JavaScript.

PHP Syntax

Instead of using the <script> and </script> tags, PHP uses to <?php and ?> tags. A normal PHP file should look like this:

Code:
 
<html>
<head>

<?php

CODE TO BE EXECUTED

?>

</head>
</html>

You can also add things like a Title for the Webpage or Document and a Comment block:

Code:
 
<html>
<head>

<title>TITLE OF FILE GOES HERE</title>

<?php

/*
This is a comment block
which can contain
multiple lines
*/

CODE TO BE EXECUTED

?>

</head>
</html>

PHP Variables

So now that we know the layout of a PHP File, we can start to add things to make it a Code. Below I will show you how to use Variables:

Code:
 
<html>
<head>

<?php

$variable="Hello!";
echo $variable;

?>

</head>
</html>


The above Code will turn out like this:
Code:
 
Hello!

When adding a Variable you need to add the money symbol $ and then your variable name after that. Then you can use echo (Just like document.write("") in JavaScript) to write out the variable. At the end of every line in a PHP Code, a semi-colon ( ; ) must be added just like in the example above.

Now to combine 2 variables together on one line, you would do the following:

Code:
 
<html>
<head>

<?php

$variable="Hello!";
$variable2="123!";
echo $variable . " " . $variable2;

?>

</head>
</html>

The output of the above Code would look like this:
Code:
 
Hello! 123

Variable Rules: When writing a Variable, make sure it starts with a LETTER or UNDERSCORE.

© Nuke 2007. Not to be re-posted or edited without permission.
Offline Profile Quote Post Goto Top
 
Persephone
Member Avatar
badass turtle
Mind if i make some observations? (by which i mean be a complete bastard and make you rewrite most of it)

Quote:
 
PHP stands for PHP: Hypertext Preprocessor. PHP is a server side scripting language that is used almost everywhere. Although it can't be used on InvisionFree, it still comes in useful at times. PHP is useful for making things that JavaScript can't and mainly for making Web pages. I am currently learning PHP because I think it is more interesting than JavaScript.


Sorry, but that's pretty much awful. You really need to give some examples of where it would be used over other forms of coding, and some really good reasons. eg, rewrite what i'm sure what someone on w3schools has already written ;D

Also, please please please remove that last line. It makes you seem so disassociated from the subject. Why would anyone want to learn off anyone who seems so dispassionate about it? They want to know it's the coolest form of coding there is. Then they'll want to learn it.

I'd also advise you put in more about this being recognizing the setup of a PHP file and explanation of what the simple commands do more, or even likenesses - for example, i'm pretty sure that echo is a php equivalent of javascript's document.write, and i'm interested in what the differences are. (yes, i'm aware you pointed out the likeness, but what are the exact differences? why should i be using PHP here instead of javascript?
Offline Profile Quote Post Goto Top
 
Persephone
Member Avatar
badass turtle
PIE IST KREIG.

KREIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIG.

on the food chain:

vegitation > insects > birds > cats > dogs > badass turtles > humans > horses > humans who aren't under 5 foot > gaseous entities > gods > matter > energy > pie
Offline Profile Quote Post Goto Top
 
Wolt

Pie is legion.
Offline Profile Quote Post Goto Top
 
Persephone
Member Avatar
badass turtle
i am rather fond of the badass turtles though, it has to be said.
Offline Profile Quote Post Goto Top
 
carnivalxx
Member Avatar

apple pie fucking rapes.
Offline Profile Quote Post Goto Top
 
Nuke
Member Avatar

Dude, it's a basic tutorial I wrote last year about PHP, not WHY it is better than other forms of coding or compare it to other coding languages. I'm allowed to add my own copyright, it doesn't make the tutorial less cool at all. If you don't like it, trash it.

Edit: I have compared it to Javascript several times in my tutorial:
Quote:
 
Instead of using the <script> and </script> tags, PHP uses to <?php and ?> tags.

Quote:
 
Then you can use echo (Just like document.write("") in JavaScript) to write out the variable.

I have also edited the introduction bit to save both of us a lot of time, not because I think your right. ;)
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
ZetaBoards - Free Forum Hosting
Create your own social network with a free forum.
Learn More · Sign-up for Free
« Previous Topic · Just Let Loose · Next Topic »
Add Reply