1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP include/require without executing the code?

Discussion in 'PHP' started by atxsurf, Feb 16, 2009.

  1. #1
    I was always wondering is there any way to "include" or "require" another php file that contains both the main code and functions without executing the main code (so to use an ordinary php script with some functions in there as a library)? Or at least suppress the stdout thrown by the main code from the file included?
     
    atxsurf, Feb 16, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Use output buffering.

    ob_start();
    include 'file.php';
    ob_end_clean();
    PHP:
     
    Danltn, Feb 16, 2009 IP
  3. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #3
    The is a design issue, if you have functions common to more than one page you should put the functions in a separate file and include it from both pages.
     
    m0nkeymafia, Feb 16, 2009 IP
  4. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #4
    Use functions in your include file - they will not execute without calling them :)
     
    ActiveFrost, Feb 16, 2009 IP