Re: including an HTML file
| From: | The Disguised Jedi | Date: | Sun, 16 Jan 2005 21:27:54 +0000 |
| Subject: | Re: including an HTML file | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-25347@lists.php.net to get a copy of this message | ||
Well, fread reads the entire file, and we need to check the lines to
see if they contain our tag, and so that is why i used fgets. fread
also puts the entire file into RAM, and that can cause memory problems
with large files. But, I forgot a few pieces of my function, so I'm
adding a better version.
<?php
$filename = 'ourfile.html';
$tag = '<BODY>';
$closing_tag = '</BODY>';
function insert_html($filename, $tag, $closing_tag) {
//Open the HTML file
$handle = fopen($filename, 'r');
$i = 0;
//As long as the file reader isn't at the end of the file, keep looping through
while (!feof($handle)) {
//Read through our file in 4MB chunks, or by line, whichever comes first...
$buffer = fgets($handle, 4096);
//Search our buffer for the tag. If it is there, we tell the rest
of the program to start saving out the text...
if (strstr($buffer, $tag) == $tag) {
$save = true;
}
if ($save == true) {
$file[$i] = $buffer;
$i++;
}
if (strstr($buffer, $closing_tag) == $closing_tag) {
$save = false;
}
}
//Put the data all together, and send it back...
while (current($file)) {
$data .= '
' . current($file);
}
return $data;
}
?>
I forgot to add the part that tells it to check for when to stop
saving. This should suit your needs Gaetono, let me know if it
doesn't work right!
--
The Disguised Jedi
disguised.jedi@gmail.com
PHP rocks!
"Knowledge is Power. Power Corrupts. Go to school, become evil"
Disclaimer: Any disclaimer attached to this message may be ignored.
This message is Certified Virus Free