Activity Stream
48,167 MEMBERS
6919 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 10 of 10
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default PHP Tutorial ( Creating Functions ).

    Heya again,

    ok so this time ive decided to show you how to create functions and discuss the pros and cons of this..

    A function is a block of code the performs a certain task, such predefined functions your are probably familiar with such as
    • trim()
    • print()
    • nl2br()


    but if you want to perform a task several times throught a webiste you dont wna tto have to write the code every time you need to perform it.

    so functions are a way to create a block of code that is stored in the memory of php and can be called over and over again.

    Heres how you create a function:
    PHP Code: 

    /*
    A function has to have the following.
    1.A Name
    2.Variables (if any).

    to create a function the first word should be the word function and then followed by the name of the function your making

    function MyFunctionName

    and then followed by brackets like so

    function MyFunctionName()

    and then finally it should have a pair of braces like so

    function MyFunctionName(){}

    If we add this to a php script it will work but its useless as we have only defined a function and not done anything with it yet so lets do that now.
    */
    //#1
    function MyUrl(){
         return 
    'http://www.litewarez.com';
    }
    #2
    function MyUrl(){
         echo 
    'http://www.litewarez.com';
    }

    /*
    Ok so as you can see theres a difference beetween #1 and #2 ...


    #1 only returns the data to the origin it was called
    #2 this will print the data to the origin it was called
    */

    //Lets call them

    MyUrl(); // you will not see anything on your screen as #1 is returned
    myUrl(); // this will print your url to the screen as you have echo'ed it within the function 

    /*
    Its always better to return data from a functions as this allowes you to 
    move data around the script without any of the users seeing the data 
    on there screen
    */

    /*
    Ok so lets work with parameters.

    Parameters allow you to send a string or an object directly into the function to process, below are some examples.
    */

    function MakeBold($String){
          return 
    sprintf("<strong>%s</strong>",$String);
          
    //this will replace %s with your $string
    }

    //Usage

    $Plain_string "I Love Litewarez.com";
    $Bold_string MakeBold($Plain_string);

    //Plain_string = I Love Litewarez.com
    //Bold_string = <strong>I Love Litewarez.com</strong>

    Example 2.
    //heres an example of performing more complex code within a function

    function GetWebData($url NULL){
          if(
    strlen($url) < 5){
                return 
    "Url too short";
          }
          if(
    function_exists("file_get_contents")){
                
    $Website_data file_get_contents($url);
          }else{
                return 
    "Funtion (file_get_contents) does not exists. please upgrade php";
          }
          if(
    strlen($Website_data) != 0){
                return 
    $Website_data;
          }else{
                return 
    "0 Bytes of data retrieved from " $url;
          }
    }

    //Now you can just use this command to grab data from a website wherever 
    //and whenever you need to perform this task

    $Grabbed_html GetWebData("http://www.SomeSite.com");

    /*
    You can use this as many times as you wish and if you want to read more
    about creating functions just google "Create php functions"
    */ 
    Well hope you understood it and please comment if you like

    Peace
    litewarez Reviewed by litewarez on . PHP Tutorial ( Creating Functions ). Heya again, ok so this time ive decided to show you how to create functions and discuss the pros and cons of this.. A function is a block of code the performs a certain task, such predefined functions your are probably familiar with such as trim() print() nl2br() Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    Plutost.com OffshorePort.net Desi-Mobilez.com PhotoshopDesigner.co.uk TutsBy.me BabesWallpapers.net
    I'm soon going to learn C++ & I have heard that PHP is similar to C++
    Plutost.com Asia & Europe Hosting Provider / Offshore Shared/VPS Hosting / Even Better than Gold
    WHMCS License Verify (Catch those scam hosts)
    Tutorials By .Me

  4.     
    #3
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    yes and java
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  5.     
    #4
    Member
    There are tonnes of different PHP functions. Such as ip2long, stripslashes, fread & fwrite.

  6.     
    #5
    Banned
    Quote Originally Posted by Plutost View Post
    I'm soon going to learn C++ & I have heard that PHP is similar to C++
    Learn VB first cause Visual Basic is easier and is more related to PHP.

  7.     
    #6
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    to be honest i think before you attempt to learn new programming langs you should first understand what you want to become, for instance if you want to become a website developer then learn the following in order

    *(x)HTML
    *CSS
    *XML
    *Javascript
    *PHP
    *MySql
    *ASP
    *JAVA

    But if you want to become a software engineer then you should first take a look at what OS you wish to program for i.e Windows, Linux, Mac, Other

    then you should learn the architecture for the system and then learn the languages for that particular one

    Personally Im a Web Developer and I have a job and a career set...

    Peace
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  8.     
    #7
    Respected Developer
    Website's:
    PlatinumW.org NexusDDL.com HD-United.org CheckLinks.org FLVD.org
    I personally prefer the naming convention of first letter small and others big just like javascript. Nice tut though

  9.     
    #8
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    yea i usually write my vars and functions as HelloWorld but when im just bombing threw a quick script ill just do lowercase for speed lol
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  10.     
    #9
    Member
    Website's:
    WareztheDDL.com GTFO.ws
    is there any advantage of using UpperCase?
    i use for javascript, but just wondering if it has advantages/disad's using it in php?

  11.     
    #10
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    EDITED**

    with php it works as follows

    1 character acts as a set amount of bytes so A and a have the exact same length and will not effect speed of your scripts

    all tho if you are creating a script that others will read and edit for personal uses i would keep to industry standers and go with the flow of
    lowercase first followed by lowercase until a new word then you use an uppercase to to show "visually" that there are several words.. for instance:

    litewarezzoo => litewarezZoo
    warezcoders => warezCoders
    firstsecond => firstSecond

    all tho some people tent to use _ "underscores" between words to help visability but this adds extra length to your script size and processing speeds....

    peace
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Tutorial for Creating Vbulletin Theme ?
    By warezrock in forum Tutorials and Guides
    Replies: 7
    Last Post: 27th Apr 2011, 09:25 AM
  2. Tutorial [Creating a PHP Framework] {advanced} (PART 4)
    By litewarez in forum Tutorials and Guides
    Replies: 1
    Last Post: 9th Feb 2010, 04:24 AM
  3. Tutorial [Creating a PHP Framework] {advanced} (PART 1)
    By litewarez in forum Tutorials and Guides
    Replies: 1
    Last Post: 30th Jan 2010, 03:37 PM
  4. PHP Tutorial (Creating Classes)
    By litewarez in forum Tutorials and Guides
    Replies: 0
    Last Post: 14th May 2009, 11:40 AM
  5. Tutorial - Creating Signatures in Photoshop
    By rich5lee in forum Tutorials and Guides
    Replies: 0
    Last Post: 28th Jul 2008, 05:14 PM

Tags for this Thread

BE SOCIAL