Problem With Require

Discussion in 'PHP' started by Jeremy Benson, Jun 30, 2014.

  1. #1
    Hey,

    I have this profile page where I'm going to interpolate different bits of html through php's require function. The problem is when I include, or require, the html may page div drops down 12 or px. I don't have a clue why. I put the html in the php file...required it.. the divs dropped down... I put the html back in the page where I got them from and they went back to normal..

    Is there any normal explanation why? I don't really want to include code first off, because it's a pretty good chunk, but it shouldn't matter.. I tried doing this several times with the same results and the html, as far as I can tell, was always cut from the same place...
     
    Jeremy Benson, Jun 30, 2014 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    1) Remove all closing tags for the PHP files.
    2) Insure files are saved UTF8 without BOM (check your editor docs for howto).

    Finally debug the issue using var_dump on each file, see the exact line the issue occurs on.
     
    ThePHPMaster, Jun 30, 2014 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,875
    Likes Received:
    4,547
    Best Answers:
    123
    Trophy Points:
    665
    #3
    I'd put an html comment at the start and end of the pages - then view the source to see if anything odd has been put in. Use inspect to find the extra divs - can really help isolate where the problem is.

    and finally, when you include/require a file ensure that any tags it opens, it also closes
     
    sarahk, Jun 30, 2014 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    My tip is that the HTML you include/require is a complete HTML-file, with html and head-tags etc. Maybe you even load included files several times.
    I've never understood the reason for including HTML-files in PHP - just make a combined PHP-file, which has the HTML in the file itself, echoed out.
     
    PoPSiCLe, Jul 1, 2014 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,875
    Likes Received:
    4,547
    Best Answers:
    123
    Trophy Points:
    665
    #5
    If you look at this page - that the thread is displayed on - there will be lots of includes and segments of incomplete html. At a bare minimum there will separate code for
    • header
    • advertising
    • navigation
    • analytics stuff
    • twitter feed
    • thread content
    • navigation
    • footer
     
    sarahk, Jul 1, 2014 IP