BBGameZone.net PBBG Network | BuildingBrowserGames | Top-PBBG
September 03, 2010, 02:03:04 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the Browser-Base Game Zone forums!
 
  Home   Forum   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Introduction to PHP  (Read 1352 times)
Zeggy
Global Moderator
Level 35
*****

Reputation: 10
Offline Offline

Posts: 1,148



View Profile WWW
« on: August 31, 2006, 06:38:38 AM »

What is PHP?

PHP is a server-side scripting language. This means that all the PHP code is processed server-side, unlike HTML, so PHP code is usually not for the public to see. It is used for creating dynamic pages.

Using PHP

To begin with, PHP begins and ends with php tags. Everything within these tags will be processed:
Code:
<?php

//Code here

?>

Some alternative tags:

Code:
<?

//Code here

?>

These tags must be specially configured first:
Code:
<%

//Code here

%>



<SCRIPT LANGUAGE="php">

//Code here

</SCRIPT>


Hello World!

As a first example of using PHP, we will 'echo' the text "Hello World!":

Code:
<?php

echo "Hello World!";

?>

As you can see, the code begins with the PHP tags, and includes this line:
echo "Hello World!";
It's ended by a semi-colon, which is used to end all statements.
The echo function basically just prints the text within quotes onto the browser screen. Double quotes and single quotes can be used.

Variables

In PHP, variables are used to store data that can be changed. PHP's variables, unlike C/C++ or Java, can be of any type, so can also be used without specifying a type:

Code:
<?php

$variable 
"I'm a string!";

echo 
$variable;



$variable 1;

echo 
$variable;

?>

In this example, the variable has changed its content and its type, from a string into an integer. Both variables' contents are printed on the screen. In this example, the echo function does not use double or single quotes becuase it only prints out a variable. Anything else, including a combination of variable and text will have to be included within quotes.


Remember

PHP is supposed to be used with HTML. You can echo the HTML within PHP, sure, but it is much better to seperate the HTML and PHP:

Code:
<html>

<head>

<title>Hello!</title>

</head>

<body>

Hello, <?php

$name 
"Andy";

echo 
$name;

?>


</body>

</html>

This would print "Hello, Andy". The HTML could have been included in the PHP but it becomes a pain to understand the source when the web page becomes more complicated and large.
Logged
KingMonkey Throughout!
Somebody Told Me!
Level 13
*

Reputation: -14
Offline Offline

Posts: 102



View Profile
« Reply #1 on: September 27, 2006, 10:39:40 AM »

A bit more Smiley

Include a page
Code:
<?php
include("File name");
?>

That will run that file on the page you insert that code into
 
Require to run page once!
Code:
<?php
require_once("File name");
?>

This will Make the code only use the file once.

Show Text

Code:
<?php
print"Whoooo im great";
?>

That will come up as 'Whoooo im great' on the page that its on. You can also use echo instead of print.
 
Logged

PHP Game Programer!

Sava
Level 13
*

Reputation: -12
Offline Offline

Posts: 101


It's just me


View Profile
« Reply #2 on: September 28, 2006, 04:07:47 PM »

the elementary but great description. Really nice.

I have one using the include function:


so you have a variable.php
Quote
<?php
$color = 'blue';
$item = 'sky';
?>

and an index.php

Quote
<?php
echo 'The $item is $color'; // and you get only The is
?>

but if you also include the variable.php

Quote
<?php
include('variable.php');

echo 'The $item is $color'; // and you will get the right thing  The sky is blue

?>
Logged

smiley
Level 13
*

Reputation: -7
Offline Offline

Posts: 101


View Profile
« Reply #3 on: September 30, 2006, 06:30:39 AM »

I want to learn php.
Logged
smiley
Level 13
*

Reputation: -7
Offline Offline

Posts: 101


View Profile
« Reply #4 on: September 30, 2006, 06:40:30 AM »

I want to learn php and hi_118 said i could learn it here.
Logged
Mgccl
Level 7
*

Reputation: 1
Offline Offline

Posts: 33


View Profile WWW
« Reply #5 on: November 09, 2006, 10:54:36 PM »

normally... echo is coooool and fast
unless you have output buffer... then print is faster...

But.. when you got smarty... why do you have to care about echo and print anymore...
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
SimplePortal 2.2 © 2008-2009
Valid XHTML 1.0! Valid CSS!