Simply Cutting Edge
Welcome Guest [Log In] [Register]
Welcome to zetaNetwork. 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 viewing zetaNetwork exclusive tutorials and articles, and access to our code snippets section. Registration is simple, fast, and completely free.


Click Here To Register


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

Username:   Password:
Add Reply
PHP Basics
Topic Started: Jun 4 2011, 01:01 PM (15,617 Views)
Fable
Member Avatar


PHP Basics
You should already know: HTML, CSS and JavaScript

First off, you cannot write and run PHP scripts from Zetaboards or simply from the browser like you would JavaScript. You either need some installation of an Apache Web Server with PHP installed to test your scripts on or better yet some web hosting from which to conduct your scripts. The are some free web hosting which offer both PHP and MySQL 000webhost.com is not a bad start. I've used both 000webhost.com and freehostia.com which is my favourite. You can of course shell out a little cash for much better services. I use 34sp.com which is a great UK web hosting company with a great support service.

With that said lets get on.
What can PHP do in terms of Zetaboards Mods?
The benefit of PHP is that it can run things off of the forum and can do so whenever it is called. It can also help to store information that can be accessed by all. JavaScript is good but it only runs off of the information given to it in a client setting. Because PHP is server side is can give and get information from everyone.

Lets get going!
Ok so first step is to create a PHP file. Simply create a new file and call it "mytest.php". The .php file extension tells the software that this is a PHP script and will therefore treat it like one. Inside a PHP file we can add HTML, CSS, JavaScript and PHP. A simple PHP script might look like this
Code: HTML
 
<!DOCTYPE html>
<html>
<head>
<title>My Test</title>
</head>
<body>
<?php
echo "<p>Hello world!</p>";
?>
</body
</html>
This would display a page with a paragraph saying "Hello world!". PHP has similar constructs to other programming languages such as variables, loops, arrays, in built functions. It also can be OO (Object Oriented). This means that you can create classes which holds values and performs certain functions. Classes are the in depth description of what an object is. And Object is something that has been created using the class of that object. For example:
Code:
 
class test {
function helloWorld(){
echo "hello world";
}
}

$test = new test();
$test->helloWorld();
The first section defines the class test and the last two lines creates the variable $test and creates the object of the class test to that variable (In fact it only assigns a reference to the variable, a reference which accesses the object). We then see in the last line that the variable now can be used to call the methods from the test object, in this case the helloWorld() method, which prints "hello world!" to the page. Note: All PHP variables are prepended by a $. They don't need to be declared before hand and can change type dynamically. e.g.
Code:
 
$a = 1; // Int
$a = "hello"; // String
$a = true; // Boolean
If you call $a at the last line you have a boolean variable.

To end with, here are some basic features of PHP that you might find helpful:
For loop:
Code:
 
for($x=0; $x<10; $x++){
... body of code ...
}
Foreach loop:
Code:
 
foreach($many as $single){
... body of code ...
}
While loop:
Code:
 
while($x != true){
... body of code ...
}
Arrays:
Code:
 
$arr = array(1, 2, 3, 4, 5);
$arrTwo = array("key1" => "value1", "key2" => "value2");
Multidimensional Arrays:
Code:
 
$arr = array("key1" => array("key" = >"value"), "key2" => "value2");


Doc. donated by Hacks and Mods
Posted Image
Offline Profile Quote ^
 
Pro
Member Avatar
Underground Coding

This tutorial has been found to be about PHP and has been moved to the PHP section.

Pro | zetaNetwork Staff
Pro | zetaNetwork Instructor & Admin
I Coded Most Of The Smexy Stuff You See :P
PM Me Any Questions
Need live support? Click here.
Offline Profile Quote ^
 
Peter Malota
Rules


In how many ways we can retrieve the data in the result set of
MySQL using PHP?
Uk Education in India
Offline Profile Quote ^
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Tutorials · Next Topic »
Add Reply