Include statement within other php code...POSSIBLE?

Discussion in 'PHP' started by ian_ok, Jan 29, 2007.

  1. #1
    To show RAW data from my database without any formating or fields info I use this:
    <?php renderSingleListingItemRaw($listingID, "data") ?>
    PHP:
    So what I want to do is use an include statement that will output this data and from that include a file from another folder location, such as the file below.

    <?php include './folder/fileA.html' ?>
    PHP:
    Is this possible?

    E.G.
    <?php include './folder/renderSingleListingItemRaw($listingID, "data").html' ?>
    PHP:
    Which doesn't work!!

    Thanks Ian



    Thanks Ian
     
    ian_ok, Jan 29, 2007 IP
  2. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've managed to do with the following, it's not what i fully wanted and means renaming a few files, but it does the job.

    <?php include './folder/' . $listingID . '.html' ?>
    PHP:
    Ian
     
    ian_ok, Jan 29, 2007 IP
  3. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #3
    could NOT have worked because you forgot the ();

    hence if you want to test try syntax like

    <?php include ('folder/fileA.html'); ?>

    unless you KNOW why you want to include a html file
    and unless you have no other choice - I recommend you call the file to include some different file extension - may be

    fileA.tpl

    why ?

    if EVER you want to parse HTML files for PHP-SSI includes - then you surely want to include text module used for your include().

    re your paths in include()
    always keep in mind that - my experience - include() does NOT accept absolute server paths like

    /folder/subfolder/file.tpl

    but works fine with:

    1. relative paths
    2. full URLs ( starting http://...)
     
    hans, Jan 29, 2007 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    Have you tried something like this?

    
    <?php 
    include './folder/'.renderSingleListingItemRaw($listingID, "data").'.html' ?>
    
    PHP:
    Assuming the function returns only a valid filename, and that file actually exists, this should work.
     
    jestep, Jan 29, 2007 IP
  5. brendandonhue

    brendandonhue Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    From the PHP manual:
    Because include() is a special language construct, parentheses are not needed around its argument.
     
    brendandonhue, Jan 29, 2007 IP
  6. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The php manual contains this caution about using include:

    In my own work, I would never include an html file. I would open the file and read it into an array, do whatever my script needed to do with the file contents, and then continue with my script -- whether displaying something to the screen or doing something else.
     
    clancey, Jan 29, 2007 IP
  7. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Now you can't. The function above opens,reads and outputs the file info, which are not includeable.

    You can only include files, not file content.

    Peace,
     
    Barti1987, Jan 29, 2007 IP
  8. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks for all the feedback etc..

    Am I right in thinking that some of you are saying you 'SHOULD NOT' use a .html as an include for security issues???

    eg
    <?php include './folder/fileA.html' ?>
    PHP:
    If so why...?
     
    ian_ok, Jan 31, 2007 IP
  9. brendandonhue

    brendandonhue Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It's fine to include an html file from your own server. You shouldn't include files that aren't trusted because they could contain malicious code. readfile() would be better in that case.
     
    brendandonhue, Feb 3, 2007 IP