hosted by liquidweb


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

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
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 04-27-2006, 10:35 PM
osphere osphere is offline
Sexy Mariachi
 
Join Date: Nov 2004
Location: Mexico City
Posts: 731

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?


Reply With Quote


Sponsored Links
  #2  
Old 04-27-2006, 10:39 PM
RWJDCom RWJDCom is offline
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

Reply With Quote
  #3  
Old 04-27-2006, 10:53 PM
osphere osphere is offline
Sexy Mariachi
 
Join Date: Nov 2004
Location: Mexico City
Posts: 731
Thanks man, it works perfectly, Thanks!

Reply With Quote
Sponsored Links
  #4  
Old 04-27-2006, 11:12 PM
Saeven Saeven is offline
Web Hosting Master
 
Join Date: Aug 2002
Location: Canada
Posts: 644
Even simpler:

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

__________________
Senior Architect, saeven.net consulting inc.
Zend Certified Engineer
Saeven|CRM (helpdesk/email/livechat) : http://crm.saeven.net
Whois.Cart() : http://whoiscart.net

Reply With Quote
  #5  
Old 04-28-2006, 06:56 AM
bear bear is online now
Community Leader
 
Join Date: Oct 2002
Location: cognito
Posts: 17,318
Why not this?
Code:
include('file.html');

__________________
Have problems (don't we all)? Head over to the help desk
If at first you don't succeed, that's one data point.


Reply With Quote
  #6  
Old 04-28-2006, 09:44 AM
El-Vino El-Vino is offline
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...

Reply With Quote
  #7  
Old 04-28-2006, 09:51 AM
osphere osphere is offline
Sexy Mariachi
 
Join Date: Nov 2004
Location: Mexico City
Posts: 731
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

Reply With Quote
  #8  
Old 04-28-2006, 10:07 AM
mikey1090 mikey1090 is offline
Web Hosting Evangelist
 
Join Date: Feb 2006
Location: Lancashire, UK
Posts: 472
i use require "file.php";

Reply With Quote
  #9  
Old 05-05-2006, 09:41 AM
atomicshockwave atomicshockwave is offline
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

Reply With Quote
  #10  
Old 05-05-2006, 10:32 AM
TwistMyArm TwistMyArm is offline
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.

Reply With Quote
  #11  
Old 05-05-2006, 10:50 AM
nnormal nnormal is offline
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

Reply With Quote
  #12  
Old 05-05-2006, 11:20 AM
atomicshockwave atomicshockwave is offline
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

Reply With Quote
  #13  
Old 05-05-2006, 11:22 AM
TwistMyArm TwistMyArm is offline
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.

Reply With Quote
  #14  
Old 05-05-2006, 11:25 AM
nnormal nnormal is offline
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);
}
?>

Reply With Quote
  #15  
Old 05-05-2006, 11:41 AM
atomicshockwave atomicshockwave is offline
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 With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Phoenix NAP Responds to Customer Feedback with New Cloud Features Web Hosting News 2013-02-19 17:09:09
50a15ecd-2ad0-4c0e-9670-53b645a799a0 Listing 2013-03-05 18:23:07
50a15ecd-1b84-43f7-bbf7-53af45a799a0 Listing 2013-03-05 18:23:08
50a15ecd-cdbc-420c-9336-53a745a799a0 Listing 2013-03-05 18:23:08
Pancake.io, DropPages Let Users Host Web Site Files on DropBox Blog 2011-12-08 17:03:11


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?
Advertisement:
Web Hosting News:



 

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?