Results 1 to 21 of 21
Thread: PHP Import HTML external file
-
04-27-2006, 10:35 PM #1Web Hosting Master
- Join Date
- Nov 2004
- Location
- Dallas
- Posts
- 740
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?
-
04-27-2006, 10:39 PM #2Newbie
- 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;
Jeffrey J. Dodge
RWJD.Com | [url=http://www.filehost.nu]FileHost.nu
-
04-27-2006, 10:53 PM #3Web Hosting Master
- Join Date
- Nov 2004
- Location
- Dallas
- Posts
- 740
Thanks man, it works perfectly, Thanks!
-
04-27-2006, 11:12 PM #4Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
-
04-28-2006, 06:56 AM #5
Why not this?
Code:include('file.html');
Your one stop shop for decentralization
-
04-28-2006, 09:44 AM #6Newbie
- Join Date
- Feb 2006
- Posts
- 13
Originally Posted by bear
require('file.html');
if the file is mandatory and you want the loading to die if it's not found...
-
04-28-2006, 09:51 AM #7Web Hosting Master
- Join Date
- Nov 2004
- Location
- Dallas
- Posts
- 740
Originally Posted by El-Vino
Thanks
-
04-28-2006, 10:07 AM #8Web Hosting Evangelist
- Join Date
- Feb 2006
- Location
- Lancashire, UK
- Posts
- 474
i use require "file.php";
-
05-05-2006, 09:41 AM #9Newbie
- 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
-
05-05-2006, 10:32 AM #10Newbie
- 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.
-
05-05-2006, 10:50 AM #11Web 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');
?>
-
05-05-2006, 11:20 AM #12Newbie
- 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
-
05-05-2006, 11:22 AM #13Newbie
- 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.
-
05-05-2006, 11:25 AM #14Web 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);
}
?>
-
05-05-2006, 11:41 AM #15Newbie
- 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.
-
05-05-2006, 02:57 PM #16Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
Never EVER use $_GET in conjunction with file commands directly:
isfile($_GET['p'].'.html')
Code:switch( $_GET['p'] ){ case 'file1': include( 'file1.html'); break; //... default: include( 'default.html' ); }
}
-
05-07-2006, 06:04 AM #17Newbie
- Join Date
- May 2006
- Location
- Uk
- Posts
- 11
use the include() function
-
05-07-2006, 06:22 AM #18Newbie
- Join Date
- May 2006
- Posts
- 20
never heard of the include() function gedevelopment
could you give me some more info in that function? vbmenu_register("postmenu_3851379", true);
-
05-07-2006, 06:27 AM #19Newbie
- Join Date
- May 2006
- Location
- Uk
- Posts
- 11
ok, lets say you have a 1 page site. you have a php file and then use a html template to make life easier to edit the page visually. (in say frontpage etc)
you would use the include() to put that html code into the page and display it.
example:
HTML TEMPLATE FILE: template.html
<b> Hello And Welcome To This Test </b>
PHP FILE: index.php
<html>
<head>
<title>Some Title</title>
</head>
<body>
<?php
include ("template.html");
?>
</body>
</html>
This will display: Hello And Welcome To This Test when the index.php file is loaded. Basically it put the HTML code into the php code. Makes visual editing of pages alot easier.
-
05-07-2006, 06:48 AM #20Newbie
- Join Date
- May 2006
- Posts
- 20
thanks gedevelopment!
I like your idea to use the include()
and using that basic idea I found this on the web, it needs some adjustment, but I think it just might work:
linker.php ( this page is to autolink textfiles in your directory)
-------------
<table border="1" bordercolor="#000000" align="center" WIDTH="75%"><tr
bgcolor="#999999"><td><font
color="#000000">Name</font></td><td><font color="#000000">Size</font></td></tr>
<?php
exec("ls -la $dir",$lines,$rc);
$count = count($lines) - 1;
for ($i = 1; $i <= $count; $i++) {
$type = substr($lines[$i],0,1);
$name = strrchr($lines[$i]," ");
$name = substr($name,1);
$dire = substr($lines[$i],0,strpos($lines[$i],$name));
// echo "$dire</font>"; //
if ($type == "d") {
if ($name == "." or $name == "..") {
;
} else {
if ($dir == "") {
$size=filesize($name);
echo "<tr bgcolor="#999999"><td><a href="$name">$name</a></td><td>$size</td></tr>";
} else {
$size=filesize($name);
echo "<tr bgcolor="#DDDDDD"><td><a href=$dir/disp?i=$name>$name</a></td><td>$size</td></tr>";
}
}
} else {
if ($dir == "") {
$size=filesize($name);
echo "<tr bgcolor="#999999"><td><a href=disp.php?i=$name>$name</a></td><td>$size</td></tr>";
} else {
echo "<tr bgcolor="#DDDDDD"><td><a href=$dir/?i=$name>$name</a></td></tr>";
}
}
}
?>
</table><br>
disp.php (this page is to display the textfiles in tableized manner)
-----------------
<?php
$text_dir="/usr/home/jiwang/public_html/test"; //the file path of your textfile
$text_url="http://www.jiwang.org/test"; //this is the url of your directory
//change this below if you so desire...
?>
<center><table BORDER CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="75%" BGCOLOR="#999999"
bordercolor="#000000">
<tr>
<td><pre>
<?php
//of course you can add errors to this script. this will display them...
function error($what) {
echo "<u>doc error...</u><p>n";
echo $what;
exit;
}
if(!$i) {
echo "<title>docs</title>n</head><table><form action=$PHP_SELF><tr><td valign=top>docs: <input type=text name=i></td><td valign=top><input type=submit value=submit></form></td></tr></table>n";
exit;
}
else {$i=addslashes($i); echo "<title>documents - $i</title>n</head>n";}
$file=$text_dir."/".$i; $url=$text_url."/".$i;
if(is_file($file)) {
include ("$file");
}
else {error('file does not exist');}
?>
</pre>
</td>
</tr>
</table></center>
-
05-07-2006, 12:18 PM #21Newbie
- Join Date
- Feb 2006
- Posts
- 13
On the case of a absolutely necessary inclusion, like the one described by gedevelopment, a require() is a lot more adapted as the page would have no logical content without the html file.