Free Games Forum
Free Games Games Forums Music Forums TV Forums

  Free Games Forum Home FORUM
HOME
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN
Rules & FAQ RULES / FAQ
REPORT SPAM

Free Games Forum: Game Technology: PHP Forum:
Basics of PHP

 

 


-Pwnt-
Veteran


Apr 10, 2006, 3:02 AM

Post #1 of 8 (758 views)
Shortcut
Basics of PHP Can't Post

By reading this tutorial you should have the basic know how to execute small scripts on your php enabled servers. Note that I will not be explaining how to set up a web server + PHP.

What Does PHP Stand For?

PHP- Hypertext Preprocessor

Starting & Ending Tags


We start off by learning the 2 main tags that you must never forget, that is the starting and ending tags.

Starting

Code
<?php

Ending

Code
?>

Basic Syntax

Now that you know about the starting & ending tags, let's start with a basic script.

Code
<?php   
echo "This is my first php script!";
?>

So you have noticed echo, echo is simple, it outputs the text, "This is my first php script!", now you must end this with a semicolon. Why? The semicolon is a separator and is used to distinguish one set of instructions from another.

Variables

Now that you know some basic syntax let's start working on variables, variables are tons of fun and one of the most important parts of PHP.

Code
<?php   
$myfirstscript = "This is my first php script!";
echo $myfirstscript;
?>

So you have noticed $myfirstscript, I made the variable $myfirstscript that holds the string "This is my first php script!". Then of course just echoed the variable which would output "This is my first php script!".

Comments

Comments are also another important thing not only in PHP but all languages. They're used to disable any type of information inside them from actually executing with your script which of course would likely cause errors.

Code
//This is a comment   
/*This is
a
comment block*/

Condition Statements

Now these are fun to play with, they are used to execute certain codes on a condition.

Code
<?php   
$mybrowser = "Fire Fox";
if ($mybrowser == "Fire Fox") { echo " You are using firefox!"; }
else { echo " You are not using firefox"; }
?>

So here I have set a variable equal to my browser then made a condition, if my browser is equal to firefox, output "You are using firefox" else (if your using something else) output "You are not using firefox". Of course this will not work until I add more to it but it gives you all a idea how condition statements work.

Looping


Looping is used for many many things, there are more then just one loop statement, I'll explain how to do the "While Loop".

Code
<?php   
$z = 1;
while ($z <= 5) {
echo $z;
$z++
}

Again I made a variable named z with the value of 1, then stated while z is less or equal to 5

Code
while ($z <= 5)

output the value of z

Code
echo $z

increase z by 1

Code
$z++

Which would output 1-5 on your page. Simple isn't it?

Forms


Now I'm assuming you have some basic understanding of html, although i will give an example of the html form but i will not be explaining it.

Code
<form action="form.php" method="post">   
Name: <input type="text" name="name">
<input type="submit" value="Submit">

That's the html form, very simple. Now to the fun part.


Code
<?php   
$name = $_POST["name"];
echo "Hello ". $name;
?>

Now here you have noticed something new and that would be "$_POST["name"]", $_POST is a variable already set by php, it received the information given in the html form, notice the name="name" in the html form and ["name"] in $_POST.

Now this is the end of my small basic tutorial, you should now have the knowledge to execute simple scripts on your servers.


brb eating spaghetti

(This post was edited by -Pwnt- on Jul 29, 2007, 3:21 AM)



coolgreen44
Senior Member

Sep 10, 2006, 6:15 PM

Post #2 of 8 (629 views)
Shortcut
Re: [-Pwnt-] Basics of PHP [In reply to] Can't Post

What do you mean by adding more? Refering to "<?php
$mybrowser = "Fire Fox";
if ($mybrowser == "Fire Fox") { echo " You are using firefox!"; }
else { echo " You are not using firefox"; }
?>"


But following that if I put


Quote

<?php
$mybrowser = "Internet Explorer";
if ($mybrowser == "Internet Explorer?") { echo " You are using IE!"; }
else { echo " You are not using firefox"; }
?>


That would be correct right?

And for your last thing, how would I get that to work, I dont really understand.


Cybernations


duler700
Member

Jan 24, 2007, 2:11 PM

Post #3 of 8 (514 views)
Shortcut
Re: [coolgreen44] Basics of PHP [In reply to] Can't Post

You could tell a 'bit on what program you should write PHP coding on. Because, I don't know. :P


-------------------------------------------
Oh... how I love this forum.. [8/15/08


jabman
Senior Member


Jan 30, 2007, 4:06 PM

Post #4 of 8 (501 views)
Shortcut
Re: [coolgreen44] Basics of PHP [In reply to] Can't Post


In Reply To
What do you mean by adding more? Refering to "<?php
$mybrowser = "Fire Fox";
if ($mybrowser == "Fire Fox") { echo " You are using firefox!"; }
else { echo " You are not using firefox"; }
?>"


But following that if I put


Quote

<?php
$mybrowser = "Internet Explorer";
if ($mybrowser == "Internet Explorer?") { echo "You are using IE!"; }
else {echo "You are not using firefox"; }
?>


That would be correct right?

And for your last thing, how would I get that to work, I dont really understand.


Nein, that would be incorrect.


Code
<?php    
$mybrowser = "Internet Explorer";
if ($mybrowser == "Internet Explorer") { echo " You are using IE!"; }
else { echo " You are not using Internet Explorer"; }
?>



You were close, you just put you're not using firefox and ? after internet explorer.


God-
Leader of peace and prosperity.
Bringer of war and violence.


t0nersxb0ners
Newbie

Feb 4, 2007, 1:26 PM

Post #5 of 8 (483 views)
Shortcut
Re: [coolgreen44] Basics of PHP [In reply to] Can't Post

The first part was already explained... that if statement would return false.

Anyway, onto your second part of your question. You really can't get that to work. There is a way to detect a browser in PHP (I don't personally know it)
But javascript is a lot more reliable to detect the type of browser. But even then, browsers are constantly updating, it is hard to keep up. I would try to avoid using any type of browser detection and just follow all W3C web standards while coding.


In Reply To
That would be correct right?

And for your last thing, how would I get that to work, I dont really understand.

On another note, that was a very nice mini-tutorial to PHP. A great start. If anyone wants to learn PHP and wants to use a "hands on" experience. I would suggest downloading some scripts and editing them. Play around with it, and you can easily pick it up


http://www.city-wars.com


angelez
Newbie

Dec 5, 2007, 7:59 PM

Post #6 of 8 (287 views)
Shortcut
Re: [t0nersxb0ners] Basics of PHP [In reply to] Can't Post

how to create a random list from show database mysql?


Anime Lyric * JPop Lyric * Metal, Rock Lyric
http://mylyric.6te.net/
Download Lyrics as Text File is available NOW


[U


-Pwnt-
Veteran


Dec 6, 2007, 1:33 AM

Post #7 of 8 (284 views)
Shortcut
Re: [angelez] Basics of PHP [In reply to] Can't Post

Elaborate.


brb eating spaghetti


karankaran
Newbie

Sep 11, 2008, 4:53 AM

Post #8 of 8 (77 views)
Shortcut
Re: [duler700] Basics of PHP [In reply to] Can't Post

check out this site
u dont have to do anyting ,, just site n make your own website ;0

www.zimplit.org

 
 
 


Search for (options) Web Design by Web Ideas - Page loaded in: 0.14 s on (CGI/1.1)