web directoryearn money in seconds   Free file hosting, free video sharing

<<< The Web Hosting >>>


Go Back   Noeman GSM > Webhosting & Website development > Website development > Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-26-2007, 04:07 PM
Spiral's Avatar
CO-Admin
 
Join Date: Sep 2004
Location: Martil
Age: 25
Posts: 15,846
Reputation: 20207
Spiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super MemberSpiral Mega Super Member
Default PHP Functions tutorial.

Today we are going to learn about a thing called a function in the scripting language of PHP.

Here are a few things about functions:

A function is a block of code that can be executed whenever we need it.

Creating PHP functions:

All functions start with the word "function()"
Name the function - It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number)
Add a "{" - The function code starts after the opening curly brace
Insert the function code
Add a "}" - The function is finished by a closing curly brace

ok!


So lets start now with a function for echoing todays date!

PHP Code:
<?php
function date()
{
echo 
date("d/m/Y");
}
?>
So there we go!

That is our first ever function...

Let's just explain that a little..

function date() - tells the server that your creating a function called date

{ -Tells the server to start accepting the code for the function.

echo date("d/m/Y"); - Using the PHP date function just to get todays date seperated by a forward slash.

} - Tells the script that the function is finished.

OK!

So there we go thats a function for us..

So now we want to echo our date somwhere on our page..

Here is an example of a HTML page, with todays date in it.

Code:
<table width="500" border="2" cellspacing="1" cellpadding="0">
  <tr>
    <td>News added by: Base </td>
  </tr>
  <tr>
    <td><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus sapien   nunc, varius ut, bibendum ac, porttitor eu, magna. Vivamus elit mauris, gravida   id, congue non, elementum eleifend, augue. Integer iaculis mauris non felis.   Morbi mi magna, ullamcorper nec, aliquam id, pellentesque sed, lorem. Curabitur   convallis fermentum augue. Donec semper iaculis est. Donec nibh. Suspendisse   semper odio id lorem pulvinar vestibulum. Suspendisse ut leo. Integer iaculis.   Sed sagittis lorem eget massa. Suspendisse vulputate mattis sem. Maecenas   elementum, libero ut consectetuer pellentesque, nibh nisl varius turpis, sit   amet accumsan libero neque in sem. </p></td>
  </tr>
  <tr>
    <td><div align="right">Date Added: <?php date(); ?>
</div></td>
  </tr>
</table>
The only thing you really need to look @ in this code is this line:
PHP Code:
<?php date(); ?>
That line just parses the contents of the function called date()

Well hope you learned somthing about functions today fokes!

my apologies for any code faults...

Will be using functions in my next tut to do with some really simple mysql stuff!


Summing up todays lesson:


To start off a funtion in php you do this:

function TheNameOfYourFunctionHere()
{ - This thing tells the server your starting off your function
Your function code goes here
} - This thing tells the server your finishing off your function

To display your function at any point you just do this:

TheNameOfYourFunctionHere();

THINGS TO REMEMBER.

You must use { & } to tell the server your starting and ending your function.

If you save your function in a seperate file (e.g. functions.php) then you HAVE to remmeber to do this tag:

<?php include("your-file.php"); ?>

More on that later!


Chow peeps
Reply With Quote
Sponsored Links
Reply

Bookmarks

Thread Tools
Display Modes

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

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


All times are GMT. The time now is 08:12 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 2004-2008 Noeman . All rights reserved
Free Advertising | Cheap Car Insurance | Loans | Problem Mortgage | Movies ratings

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112