[TUT]Introduction To PHP

Any other programming language that is not covered in the Web Scripting category.

[TUT]Introduction To PHP

Postby Jackel on Tue Jan 31, 2006 7:56 pm

I don't see any PHP post's here or maybe im over looking it, let me give it a shot Wink

What Does PHP Stand For?

PHP- Hypertext Preprocessor

Starting & Ending Tags

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

Starting
Code: Select all
<?php
Ending
Code: Select all
?>
Baisc Syntax

Now that you know about the starting & ending tag's , let's start with a basic script.
Code: Select all
<?php
echo "This is my first php script!";
?>
so you have noticed echo , echo is simple, it output's the text "This is my first php script!" , now you must end this with a semicolon , why? the semicolon is a seperator 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 ton's of fun and one of the most important part's of PHP.
Code: Select all
<?php
$myfirstscript = "This is my first php script!";
echo $myfirstscript;
?>
So you have noticed $myfirstscript , i made the variable $myfirstscript that hold's the string "This is my first php script!" . Then ofcourse just echo'd 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 , there used to disable any type of information inside them from actually executing with your script which ofcourse would likely cause error's.
Code: Select all
//This is a comment
/*This is
a
comment block*/
Condition Statements

Now these are fun to play with , they are used to execute certain code on a condition.
Code: Select all
<?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" . Ofcourse this will not work untill i i add more to it but it give's you all a idea how condition statements work.

Looping

Looping is used for many many thing's , there are more then just one loop statement, ill explain how to do the "While Loop".
Code: Select all
<?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: Select all
while ($z <= 5)
output the value of z
Code: Select all
echo $z
, increase z by 1
Code: Select all
$z++
. Which would output 1-5 on your page. Simple isn't it?

Forms

Now im 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: Select all
<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: Select all
<?php
$name = $_POST["name"];
echo "Hello ". $name;
?>
Now here you have noticed something new and that would be
Code: Select all
$_POST["name"]"
&
Code: Select all
$_POST
is a variable already set by php , it recieved the information givin in the html form , notice the name="name" in the html form and ["name"] in $_POST.

Now this is the end of this small basic tutorial , you should now have the knowledge to execute simple script's on your server's.
deb:~$
Jackel
Newbie
Newbie
 
Posts: 1
Joined: Mon Sep 26, 2005 8:14 pm

Postby Xer on Fri Feb 17, 2006 11:34 am

nice tutorial but i think first you should post how to use php server with apache who is going to learn php should be able to see whats he is doing Smile
and in wich program to write php (notepad is good) but there are many others Smile
for me i prefer to use dreamweaver Smile
anyway im going to wait your next tutorial Very Happy
Xer
Contributer
Contributer
 
Posts: 36
Joined: Fri Feb 17, 2006 8:01 am

Postby Bugs42 on Sat Feb 18, 2006 5:48 am

Nice, very nice.

Good intro to PHP, and a good refresher for people like myself who already know a bit.
Sufficiently advanced technology is indistinguishable from magic.
Bugs42
Valued Member
Valued Member
 
Posts: 189
Joined: Sat Dec 03, 2005 6:48 pm

Postby veritas on Sat Feb 18, 2006 7:10 am

You should pick up one of those SAMS' PHP + SQL + APACHE in 24 hours books, they were really helpful to me. Chapter begins from installing the needed packages to security issues.
Image
veritas
Contributer
Contributer
 
Posts: 25
Joined: Fri Feb 17, 2006 3:43 am

Postby zogo on Sat Feb 18, 2006 7:39 am

LOTS of plagiarism on the forum lately...

http://www.webhostingtalk.com/showthread.php?p=3486875
irc.anoxs.net
#phoenix
zogo
Phoenix Veteran
Phoenix Veteran
 
Posts: 667
Joined: Thu Mar 10, 2005 5:23 pm
Location: Northern California

Postby birdfish on Sat Feb 18, 2006 6:52 pm

That's say Sad

However, I wanted to make a comment about the earlier remark regarding Notepad/Dreamweaver.

However one plans to write PHP, it will always be in a text editor of some sort. Notepad (any other text editor without syntax highlighting) is great for beginners because it requires them to look closely at their code when debugging, rather than just looking for certain highlighted words. However, once past a couple tutorials, programs like Dreamweaver (or just a regular text editor with syntax highlighting) are great help. Though I haven't used any of the newer versions of Dreamweaver, I imagine that it has incorporated an IntelliSense for PHP by now.
birdfish
Newbie
Newbie
 
Posts: 6
Joined: Sat Feb 18, 2006 6:04 pm

Postby Xer on Wed Feb 22, 2006 1:50 pm

birdfish using notepad for noob's isnt good idea they will forget about learning php or any other lang (like asm , c and others if they are going to use notpad to write there cod's in )
and btw if you like from me to send your DreamWeaver 8 tell me Smile
Xer
Contributer
Contributer
 
Posts: 36
Joined: Fri Feb 17, 2006 8:01 am

Postby SgtSlaughter on Thu Feb 23, 2006 2:34 pm

If they can't handle debugging code, then they don't deserve to explore the wonders of PHP. Razz
SgtSlaughter
Newbie
Newbie
 
Posts: 11
Joined: Wed Feb 22, 2006 3:49 am

Postby Codar on Fri Mar 10, 2006 6:56 pm

Codar
Newbie
Newbie
 
Posts: 15
Joined: Mon Feb 20, 2006 8:24 pm

Postby arn0ld on Sun Apr 02, 2006 10:30 pm

ei! also try this site, www.php-mysql-tutorial.com though it is old, it has a good tut in it. and at the end, you get to create your own guestbook! yehey!
arn0ld
Regular
Regular
 
Posts: 110
Joined: Fri Mar 31, 2006 7:09 pm
Location: Las Phelippinas

Re: [TUT]Introduction To PHP

Postby darkange on Thu Apr 13, 2006 2:55 am

Jackel wrote:I don't see any PHP post's here or maybe im over looking it, let me give it a shot Wink

What Does PHP Stand For?

PHP- Hypertext Preprocessor

Starting & Ending Tags

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

Starting
Code: Select all
<?php
Ending
Code: Select all
?>
Baisc Syntax

Now that you know about the starting & ending tag's , let's start with a basic script.
Code: Select all
<?php
echo "This is my first php script!";
?>
so you have noticed echo , echo is simple, it output's the text "This is my first php script!" , now you must end this with a semicolon , why? the semicolon is a seperator 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 ton's of fun and one of the most important part's of PHP.
Code: Select all
<?php
$myfirstscript = "This is my first php script!";
echo $myfirstscript;
?>
So you have noticed $myfirstscript , i made the variable $myfirstscript that hold's the string "This is my first php script!" . Then ofcourse just echo'd 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 , there used to disable any type of information inside them from actually executing with your script which ofcourse would likely cause error's.
Code: Select all
//This is a comment
/*This is
a
comment block*/
Condition Statements

Now these are fun to play with , they are used to execute certain code on a condition.
Code: Select all
<?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" . Ofcourse this will not work untill i i add more to it but it give's you all a idea how condition statements work.

Looping

Looping is used for many many thing's , there are more then just one loop statement, ill explain how to do the "While Loop".
Code: Select all
<?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: Select all
while ($z <= 5)
output the value of z
Code: Select all
echo $z
, increase z by 1
Code: Select all
$z++
. Which would output 1-5 on your page. Simple isn't it?

Forms

Now im 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: Select all
<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: Select all
<?php
$name = $_POST["name"];
echo "Hello ". $name;
?>
Now here you have noticed something new and that would be
Code: Select all
$_POST["name"]"
&
Code: Select all
$_POST
is a variable already set by php , it recieved the information givin in the html form , notice the name="name" in the html form and ["name"] in $_POST.

Now this is the end of this small basic tutorial , you should now have the knowledge to execute simple script's on your server's.
darkange
Newbie
Newbie
 
Posts: 10
Joined: Thu Apr 13, 2006 2:49 am

Postby pumpas on Thu Apr 13, 2006 8:15 am

I think what this tutorial is dont need to be here coz on the WWW you can find many more and better tutorials.... But now bad Wink
pumpas
Newbie
Newbie
 
Posts: 16
Joined: Thu Apr 13, 2006 7:08 am


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron