Web Hosting Forums

Results 1 to 4 of 4

This is a discussion on Subroutines in PHP? in the Hosting Talk & Chit-chat forum
I have been looking through the PHP docs, and have not found any mention of subroutines in PHP? I have a pretty simple question right ...

  1. #1
    Loyal Client
    Join Date
    Oct 2002
    Posts
    134

    Subroutines in PHP?

    I have been looking through the PHP docs, and have not found any mention of subroutines in PHP?

    I have a pretty simple question right now. Basically, the code I am using would check a form, and report the error in a $ErrorMsg variable. A subroutine would be called (that of which I cannot figure out how to define one), which outputs the HTML with the correct error code, then exits the script.

    I've been looking on writing functions, but they do not seem to be completely related to what I am trying to accomplish.

    Thanks,
    Shawn

  2. #2
    Loyal Client
    Join Date
    Oct 2002
    Posts
    8
    function dontknowwhattocallit() {
    echo "error or something"
    die(); //this will STOP script processing.
    }

    or instead of die() you can return a value, and check the status in the calling routine.

  3. #3
    Loyal Client
    Join Date
    Oct 2002
    Posts
    134
    Ok, that is excellent! Now, how would I go about calling it?

    Thanks,
    Shawn

  4. #4
    Loyal Client
    Join Date
    Oct 2002
    Posts
    8
    <?php
    myfunction(); // call the function
    ?>

    <?php
    $something=myfunction(); // if your function returns a value, it will now be stored in $something.

    ?>


    check out phpbuilder.com, and get the php manual from php.net (if you havent already) and start a-readin'!

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
  •