Go Back   vBulletin Modification Discussions > Coding Discussions > PHP Discussions, Tutorials and Help
Home Register FAQ Members List Calendar Mark Forums Read
vBSEO Info Tags

About This Page: This is a discussion on Learning PHP for the first time within the PHP Discussions, Tutorials and Help forums, part of the Coding Discussions category, at vBulletin Modification Discussions. When you're learning a programming language you may become overwelmed with the complexity. I was very overwelmed when I started to learn PHP for the first time over a year ago. After I grasped how the syntax worked I


Reply
 
LinkBack Thread Tools
Old 02-09-2007, 07:29 PM   #1 (permalink)
Junior Member
 
Join Date: Nov 2006
Posts: 11
harmor is on a distinguished road
iTrader: (0)
Learning PHP for the first time

When you're learning a programming language you may become overwelmed with the complexity.
I was very overwelmed when I started to learn PHP for the first time over a year ago.
After I grasped how the syntax worked I could learn new methods more easily.

In this article I'll be giving you tutorials on PHP.
Inorder for you to run the PHP scripts you must have a host that supports PHP (atleast 4.1.0).
I highly recommend Crimson Editor for a PHP editor

-- Writing your first PHP program --
Any file that contains PHP must have the extension .php (eg. test.php)
Open Crimson Editor and start a new document (Ctrl + n).

The first thing I'll show you is how to output text using "echo".
To output (or print) text to the browser you can use several statements.
In this article I'll be using the "echo" statement.
Outputting text using PHP is pointless in my opinion but beginners need to start somewhere.
PHP Code:
<?php
echo "This is a string";
?>
The word "echo" tells PHP to output the text between the two quotes to the screen.
The semicolon tells PHP to end the statement (in this case the "echo" statement)
I recommend that you write more "echo" statements to familiarize yourself with the syntax.

I've seen scripts where the coder repeatively uses the "echo" statement for a block of text.
To give you an idea of what I mean imagine copying the "echo" statement and pasting multiple instances of it.
Doing that is unneccesary. In my opinion it makes the code look sloppy.
The way to output a block of text is presented below
PHP Code:
<?php
echo "Hello, my name is Andrew Harmor
I'm 20 years old and I'm attending Waynesburg College
located in Pennsylvania"
;
?>
-- Variables --
Variables are going to be your friend because you'll be using them a lot.
The naming convention of a variable consists of the dollar sign and almost any name (eg. $header)
A variable cannot start with a number and it cannot have a special character anywhere in the variable name.
PHP Code:
<?php
$name 
"Andrew Harmor";
echo 
$name;
?>
The equals sign assigns the string to the variable. So when you "echo" (output) the variable it'll display
the string that is assigned to that variable.
You may have noticed that the "echo" statement does not contain any quotes.
When dealing with variables encasing them in quotes is not needed.
If you were to output a string with the variable then you'll need to use quotes
PHP Code:
<?php
$name 
"Andrew Harmor";
echo 
"Hello $name";
?>
As you can see variables and the echo statement are pretty much the same.
You can also assign variables to variables.
That may sound confusing but it works the same way as done in the echo statement.
PHP Code:
<?php
$age 
"20";
$name "Andrew Harmor, $age"
echo $name;
?>
The variable $age has the value "20" assigned to it.
The variable $name has the value "Andrew Harmor, 20" assigned to it.
So when you output the value of $name you'll see exactly that.

If you want to output the value of $age and $name by themselves you would do...
PHP Code:
<?php
$age 
"20";
$name "Andrew Harmor"
echo "My name is $name, I'm $age years old";
?>
Having a value respective to the variable name gives you greater control over how you output them.
There are some instances where you have to assign variable(s) to another variable but only do so if it's your only option.
harmor is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links

Old 12-07-2007, 10:17 AM   #2 (permalink)
Junior Member
 
Join Date: Dec 2007
Posts: 17
Kaycee is on a distinguished road
iTrader: (0)
Re: Learning PHP for the first time

Thank you for this! It's a good basic for those of us that don't really know what we're doing
Kaycee is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply
Tags:





Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


A vBSkinworks Design Recoded By vBModder.
All Code Distributed On This Site is © 2006 by it's author.
Search Engine Optimization by vBSEO 3.1.0

All times are GMT -7. The time now is 03:07 AM.
Online Users 29
Registered 1
Guests 28
Members 3364
Active Members 219
Threads 1687
Posts 7143
Top poster: Code Monkey (2203)
Welcome to our newest member, abstrakt
Most users ever online was 235, 04-11-2007 at 08:59 AM.
Speak Out! vBulletin gets the web talking!


vBulletin Setup SEO

vBulletin graphics resource images