hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP Import HTML external file
Reply

Forum Jump

PHP Import HTML external file

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
Web Hosting Master
 
Join Date: Nov 2004
Location: Dallas
Posts: 739

PHP Import HTML external file


Hi, I have a problem that I can't solve, I've searched in google, in php documentation and nothing...

I have a PHP page, and I need to import plain HTML code into the page that contains the PHP code.

The file that contains the HTML is located in the same folder...

Please someone know how to do this?




Sponsored Links
  #2  
Old
Newbie
 
Join Date: Sep 2003
Location: Pawtucket, RI USA
Posts: 23
Use somthing like...

Code:
$fd = fopen("file.html", r);
$content = fread($fd, filesize("file.html"));
fclose($fd);

echo $content;
Wherever you echo the $content your HTML file will be displayed. If you need further assistance feel free to PM me.

__________________
Jeffrey J. Dodge
RWJD.Com | [url=http://www.filehost.nu]FileHost.nu

  #3  
Old
Web Hosting Master
 
Join Date: Nov 2004
Location: Dallas
Posts: 739
Thanks man, it works perfectly, Thanks!

Sponsored Links
  #4  
Old
Web Hosting Master
 
Join Date: Aug 2002
Location: Canada
Posts: 647
Even simpler:

Code:
echo file_get_contents( "file.html" );

  #5  
Old
Community Leader
 
Join Date: Oct 2002
Location: Neck deep in it
Posts: 20,240
Why not this?
Code:
include('file.html');

__________________
Having problems, or maybe questions about WHT? Head over to the help desk!



  #6  
Old
Newbie
 
Join Date: Feb 2006
Posts: 13
Quote:
Originally Posted by bear
Why not this?
Code:
include('file.html');
or
require('file.html');
if the file is mandatory and you want the loading to die if it's not found...

  #7  
Old
Web Hosting Master
 
Join Date: Nov 2004
Location: Dallas
Posts: 739
Quote:
Originally Posted by El-Vino
or
require('file.html');
if the file is mandatory and you want the loading to die if it's not found...
Thanks to all of you guy's, Think I need to read again PHP for dummies...

Thanks

  #8  
Old
Web Hosting Evangelist
 
Join Date: Feb 2006
Location: Lancashire, UK
Posts: 472
i use require "file.php";

  #9  
Old
Newbie
 
Join Date: May 2006
Posts: 20
This is like what I have ben looking to do, only is there a way to do this if there are meany html files, and diffrent names where you dont know the names?
odd ??? I know but if anyone could help

  #10  
Old
Newbie
 
Join Date: Apr 2006
Posts: 5
You can always use your include in a loop, with a variable.

Do something like open the directory and loop through all of the files. For each file, if they match a given string template, include that file.

Should be pretty simple.

  #11  
Old
Web Hosting Guru
 
Join Date: Nov 2003
Posts: 297
no need for a loop...

PHP Code:
<?
if ((isset($_GET['p'])) && (isfile($_GET['p'].'.html'))) include($_GET['p'].'.html');
else include(
'default.html');
?>
you would call pages with index.php?p=mypage

  #12  
Old
Newbie
 
Join Date: May 2006
Posts: 20
I am a little new to php, could you explain how your code would work nnormal?
just looking at it, it looks like this still needs a file that you know the name of the file. also would this alow me to do this 10+ times in one page, and could I put this php script in a html page?

sorry for all the ????, like I said I am a little new to php. thanks

  #13  
Old
Newbie
 
Join Date: Apr 2006
Posts: 5
Absolutely. I just thought that atomicshockwave was talking about including multiple HTML files with unknown names into one PHP script.

  #14  
Old
Web Hosting Guru
 
Join Date: Nov 2003
Posts: 297
it wouldnt put multiple files in for that you may need a loop. are you trying to include each file from a directory or something?

PHP Code:
<?php
if ($handle opendir('.')) {
   while (
false !== ($file readdir($handle))) {
       if (
$file != "." && $file != "..") {
          include(
$file);
       }
   }
   
closedir($handle);
}
?>

  #15  
Old
Newbie
 
Join Date: May 2006
Posts: 20
I need to have dhtml popup window for each html file in a folder on my site, and I need the script to add the window script, because files are added and removed evry day, now my plain is that in the html files would be the window script, and the php code would find the files and run the code in the index.html file (my homepage where I need the windows.

Reply

Related posts from TheWhir.com
Title Type Date Posted
DataCloud Canada Listing 2014-12-10 12:48:31
Hostway Corporation Listing 2014-12-10 12:46:59
Beta Release of Red Hat Enterprise Linux 7 Launched Web Hosting News 2013-12-12 13:01:56
Phoenix NAP Responds to Customer Feedback with New Cloud Features Web Hosting News 2013-02-19 17:09:09
Google Drive Adds File Hosting, Improves Third-Party App Integration Web Hosting News 2013-02-08 12:46:31


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?