The PHP Tutorial thread

Toneboy

Administrator
Staff member
Here comes a thread which hopefully will have me laughing in years to come due to the simplicity of it. What's more, it's the only PHP Tutorial thread which comes to you with... theme music!

(Altogether now...) Learning PHP, I think I'm learning PHP, I really think so...

Step 1 - Using include

The main reason I got into using PHP in the first place was because I got tired of having to replace one item in the every file within a site, e.g. when you add one item onto a menu.

The way around this is to use the include command.

So if you were to add something onto that menu you might want to create a menu.php file, which can be pure html if you want.
PHP:
<a href="link1.php">Link 1</a> |
<a href="link2.php">Link 2</a> |
<a href="link3.php">Link 3</a>
Then call the file in each file by using the following line:
PHP:
...
<?php
include ("$DOCUMENT_ROOT/menu/menu.php");
?>
...
(N.B. You should use $DOCUMENT_ROOT to get to your file. You can put the http:// path but it can create problems)

To make future changes just change the menu.php file.
 

Jazz_UK

PS119:114
Toneboy - I know you are a purist and only use notepad for your web design, but for those of us who are lazy & like wysiwyg, what programs can you use to set up php pages?
 

Toneboy

Administrator
Staff member
Did someone vote for the "purist" option in the "what editor?" thread? If so, it wasn't me.

I tend to use PHP Edit, which is helpful for the most part. Some alert boxes come up in French, but as long as you remember that "oui" is yes and "non" is no then you should be okay.

www.phpedit.com for the download I believe.
 

Toneboy

Administrator
Staff member
PHP & Dates

Prior to getting into PHP I used to use a familiar piece of Javascript to put date/time properties on a page. The problem with doing this is that Javascript is client-side, so it takes all the details from the users' own PC. Not normally a problem, but it is if the user hasn't set their time correctly, or if you have date specific information on the PC.

As PHP is server-side all details from the date function are taken from the server. If you see the time at the bottom of the front page you will always see the time set within UK GMT/BST times, as that is what the server is set to.

The PHP date function is also very flexible in regards to format. Here area few examples taken from the PHP manual:
PHP:
/* Today is March 10th, 2001, 5:16:18 pm */
$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
$today = date("m.d.y"); // 03.10.01
$today = date("j, m, Y"); // 10, 3, 2001
$today = date("Ymd"); // 20010310
$today = date(?h-i-s, j-m-y, it is w Day z ?); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date(?\i\t \i\s \t\h\e jS \d\a\y.?); // It is the 10th day.
$today = date("D M j G:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001
$today = date(?H:m:s \m \i\s\ \m\o\n\t\h?); // 17:03:17 m is month
For the full list of codes, please see the page detailing all the date functions on the official PHP website:
http://www.php.net/date
 

Toneboy

Administrator
Staff member
Warning for anyone thinking of learning PHP and using the mysql_query command, be prepared to put your head through your keyboard on countless occasions when trying to remember what commands and values need apostrophes and which ones don't. :mad:

Users online back working on the front page. :p
 

Jazz_UK

PS119:114
Toneboy - Bought some php books for Christmas last year, only getting round to reading the first one this month.

All I can say is "Ouch!"

It is like learning a new language, and I am wanting to write an essay but all I can say so far is "My name is Jazz. , my age is *** and I live in Scotland"

Jazz

PS Been away from the forum for too long... holidays and not having a comfy seat at the computer (Toneboy - I may be asking for it back soon, if the house does not sell this week)
 

Toneboy

Administrator
Staff member
Jazz_UK said:
Toneboy - Bought some php books for Christmas last year, only getting round to reading the first one this month.

All I can say is "Ouch!"
Honestly Jazz, I think you'll pick it up quickly. I think part of the beauty of PHP is that your use of it can be as simple or as complicated as you need it to be.

(Of course to get users online working properly I think I'll need to go quite indepth. Wish I hadn't started looking into it!)
Jazz_UK said:
PS Been away from the forum for too long... holidays and not having a comfy seat at the computer (Toneboy - I may be asking for it back soon, if the house does not sell this week)
What chair? I don't know what you're talking about. ;) :cool: :D
 

oliverlow

New Member
have something in mind to achieve

From my own experience, learning PHP for myself and teaching others, the best way is to have a reference (e.g. php.net online manuals), and something in mind you want to achieve, a project to work on, and some friendly folks who will give you pointers.
This is what our American friends might call a 'results oriented approach'.

> All I can say is "Ouch!"

Perhaps you are jumping in at the deep end! Start with an ordinary web page, and ask, "How do I put the date and time up?".
Answer:
PHP:
Today is: <?php  print date('D, d M Y'); ?>
Then you want to fiddle with it, look up the date function to find out the different formats (or see Toneboy's post), or how to output a date of a day other than today and take it from there, a step at a time

So, Jazz, what do you want to do today?
:)
 
Top