Forum Moderators: coopster
<?
ob_start();
$thefile = fopen("______", "r");
readfile($thefile);
$str = ob_get_contents();
$str = nl2br(strrev($str));//do something to string
ob_end_clean();
echo $str;
?>
I can't figure out how to read the page's contents that this code is placed into. I want it to read the entire page and jscripts, and then render the page once everything is read. THe problem I'm having is that in IE 5.1 on Mac, my client's browser, the page loads partially, then refreshes and loads again with the full page. I'm not sure how to write the path to the file above that I've indicated with _______
Thanks!
if (!function_exists('file_put_contents'))
{
function file_put_contents($filename, $contents, $flags='', $resource_context='')
{
// note the last two parameters are not used, but are included just for PHP5 compatibility
if(!$handle = @fopen($filename, 'w'))
{
return false;
}
$written = @fwrite($handle, $contents);
@fclose($handle);
return $written;
}
}
$filename can I use the page's url
Maybe depending on the server setup. Safer is to use the file's location in the file system. PHP helps you out with a built-in variable that resolves the part of the file system to get you to web root, so it's as easy as using a URL (of course this only works if the file is on the server).
So if the file you want to read is in a subdir of your site so that you would get to it like this
[example.com...]
On the file system you get it like this
// locate the file
$filename = $_SERVER['DOCUMENT_ROOT'] . '/files/myfile.php';
// check that it exists
if (!file_exists($filename))
{
echo "Couldn't find the file."
exit; // if it's a function, use something like "return 0;"
}
// it does exist, so get the contents
$contents = file_get_contents($filename);
// output the contents to the screen
echo $contents;
//add a new comment to the file
$contents .= "This is my stupid comment"
$success = file_put_contents($filename, $contents);
if ($success)
{
echo "Eureka! it worked";
}
else
{
echo "Sorry, couldn't add your stupid comment".
}
All well and good, but have we actually gotten to your question?
Do I need to combine the code from the two posts you gave me?
If you are using PHP4, yes you do.
get a page to load everything before displaying that same page?
I still don't know what this means. In general, what I do is assign everything to variables and echo via templates at the end, but in short, this will do it
ob_start();
include('everthing.php');
echo "everything in the known universe, system memory permitting."
ob_end_flush();