Results 1 to 8 of 8

Thread: PHP Include real newbee

  1. #1
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP Include real newbee

    How can I use php to load code from an external html file (external.html)
    Want it to run instead of were "Test insert text is in table"


    <tr>
    <td class="bgy" background="images/t4.gif" height="100%"
    valign="top"><br>
    Test insert text in table<br>
    </td>
    </tr>
    <tr>


    this dose not work why?
    <tr>
    <td class="bgy" background="images/t4.gif" height="100%"
    valign="top"><br>
    <?php
    include ("http://locaalhost/external.html");
    ?>
    </td>
    </tr>
    <tr>


    external.html

    <html>
    <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>external</title>
    </head>
    <body>
    external_page
    </body>
    </html>

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by stevehendo34 View Post
    this dose not work why?
    <tr>
    <td class="bgy" background="images/t4.gif" height="100%"
    valign="top"><br>
    <?php
    include ("http://locaalhost/external.html");
    ?>
    </td>
    </tr>
    <tr>
    There may be any number of reasons it doesn't work.

    >> is the filename/path correct (did you misspell "localhost" in your script, as you did in your example above)?

    >> is your page saved as a .php file?

    >> is your computer set up to run php scripts (e.g., using xampp or other server software)?

    No way for us to know for sure, without knowing more about what's going on.

    Quote Originally Posted by stevehendo34 View Post
    external.html

    <html>
    <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>external</title>
    </head>
    <body>
    external_page
    </body>
    </html>
    Also,
    If you're including an html page inside another, it should only have the content you want included - not its own <head>, <body>, etc. That will result in messy markup that could generate errors, or at least, not display the way you want it:
    HTML Code:
    <html>
    <head>
       <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
       <title>main page</title>
    </head>
    <body>
       <!--this is the included page-->
       <html>
          <head>
             <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
             <title>external</title>
          </head>
       <body>
          external_page content
       </body>
    </html>
    <!--as you can see, you now have two head sections, etc., nested inside each other, 
    when all you really wanted was the *content* of the external page-->
    </body>
    </html>

  3. #3
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    You have to make sure the file you are trying to include to is a php file. The included file can be html if you want. Then just put this code where you want the include and make sure you make the path to the file correct like includes/include.html or just include.html
    PHP Code:
    <?php include ('include.html'); ?>

  4. #4
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    "is your page saved as a .php file?"
    "You have to make sure the file you are trying to include to is a php file"
    Are you saying external.htm has to have a .php extention

    Exact code:

    <tbody>
    <tr>
    <td height="100%" valign="top" width="1"><br></td>
    <td height="100%" valign="top"><?php include ('http://localhost/external.htm');?></td>
    </tr>
    </tbody>
    </table>
    </td>
    <td valign="top" width="1"><img src="images/t4-r.gif"
    height="187" width="6"></td>
    </tr>
    </tbody>

    external.htm content
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <p>external_page / paragraph to show up via php include above
    </body>
    </html>
    Last edited by stevehendo34; 07-21-2010 at 08:32 PM.

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    no, the file that is using the include (the file where "include('external.html');" is written) needs to use the .php extension.

    Do you have a server installed locally? If so, are any errors being generated (shown) when you run your script?

    You might also use a relative path (just "external.htm" if both files are in the same folder) instead of using the http:// address.

  6. #6
    Join Date
    Jul 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    "no, the file that is using the include (the file where "include('external.html');" is written) needs to use the .php extension."
    got ya--Im sure this what I need to do

    I am not a programmer @ all just starting on PHP kinda know HTML

    "you might also use a relative path (just "external.htm" if both files are in the same folder) instead of using the http:// address."
    Ok I was floundering and tried both.

  7. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    what is the name of the main file, including the extension (this one):
    PHP Code:
    <tbody>
    <tr>
    <td height="100%" valign="top" width="1"><br></td>
    <td height="100%" valign="top"><?php include ('http://localhost/external.htm');?></td>
    </tr>
    </tbody>
    </table>
    </td>
    <td valign="top" width="1"><img src="images/t4-r.gif"
    height="187" width="6"></td>
    </tr>
    </tbody>

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Quote Originally Posted by traq View Post
    You might also use a relative path (just "external.htm" if both files are in the same folder) instead of using the http:// address.
    I believe this is likely the problem: some settings in PHP disallow including files from other websites and if you refer to your page using "http..." then this is just like loading a page from another site. You must use the relative path to the file like has been explained above.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •