SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need an explanation of this three functinos drop your opinion!!

    I am working with objects. I have three functions where I don't undertand very well and I would like some feedback about your opinion guys.

    PHP Code:
    function strip_zeros_from_date ($marked_string="")
    $no_zerosstr_replace('*0'''$marked_string);
    $cleaned_string str_replace('*'''$no_zeros);
    return 
    $cleaned_string:
    }
     function 
    redirect_to($location=NULL){
     if(
    $location !=NULL) {
     
    header("location: {$location}");
     exit;
     }
    }

    function 
    output_message($message="") {
    if (!empty(
    $message)){
    return 
    "<p class=\"message\">{message}</p>";
    }else {
    return
    "";
    }


  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,037
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    I don't know what it is you don't understand so hopefully I'll hit what it is.

    All 3 functions have "defaults". That is, if the function is called without passing it an argument, the default parameter will be used. eg.

    function function_name($parameter_variable = 'default value')

    So if the function is called like

    function_name();

    then $parameter_value will be 'default value'

    But if it's called like

    function_name('some value');

    then 'some value' will be used for the value of $parameter_value instead of 'default value'.

    The first function replaces occurences of '*0' that might be in 'some value' with nothing (i.e. ''). And then does the same for '*'. So something like

    $result = strip_zeros_from_date ('12*0560*97');
    echo $result;

    would show 1256097

    If the second is passed a valid path the script will redirect the browser to the new location and stop running the script that function's in. I'm not sure what would happen if $location was no good, but it wouldn't be pretty.

    If the last function was called like

    $result = output_message('Hello World');
    echo $result;

    <p class="message">Hello World</p>

    would be output.

    The "if" tests check the value of the parameter to see if an argument was passed. If not then the redirect function does nothing and the message function returns an empty string.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •