File_Get_Contents Issue? D:

I am attempting to use the “file_get_contents(‘’);” function in PHP to include a file… But I am having difficulties.

Here’s my code:

$values = array();
$values[0] = $_POST["content"];
$values[1] = '<span class="footer">';
$values[2] = file_get_contents("admin/dat.php");
$values[3] = "</span><br><br>";
$values[4] = file_get_contents("admin/content.php");

$content = $values[0] . $values[1] . $values[2] . $values[3] . $values[4];
$myFile = 'admin/content.php';
$filewrite = fopen($myFile, 'w+');
$writedata = $content;
fwrite($filewrite, $writedata);

$count_my_page = ("admin/updates.php");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");

echo "Content has been saved! :D";

I have a form setup with a simple text area.
You type some text, then it goes to the save.php file which contains the above codes.
The above codes takes the content, as well as content from another file, and adds it to a file… It also increased the value of a file called “updates.php”.

Now, the ‘$values[2] = file_get_contents(“admin/dat.php”);’ part is the issue.
You see, it takes the source from the “dat.php” file.
Within that file are a bunch of codes that tell the current date and time.
Well, with ‘file_get_contents()’ function, it only shows the source of the ‘dat.php’ file…
I want it to INCLUDE the codes… Not show the source.

Well, I’ve tried using the ‘include “”;’ thing, but it only includes the file on the save page, and NOT in the file it saves to!

Oh, and I’ve tried fopen too, but that didn’t work for some reason.

Could anyone help me include this with the content that is being saved?

Thank you,


What do you mean by ‘but it only includes the file on the save page, and NOT in the file it saves to!’? What do you want to do that exactly? Can you please elaborate it once again? But as far as I know your only option to include a php code from another file is by using include/require/include_Once/require_once. Please find them in the manual and see how they are supposed to use.

And if those files are supposed to have (or are independent to output) some html then it’s fine using file_get_contents. This function does not include the files. Can you post the script/code of admin/dat.php file?


Well, on the save page, I’ve tried using the ‘include’ code to include the contents from the ‘admin/dat.php’ file.
When I use the ‘include’ code, it includes the content of that file on the ‘save.php’ file.

I just want it to show in the file that it saves to.
Nothing more.

You need to use a mix of include and the ob_ functions for this.


Instead of writing the output directly PHP will create a buffer when you call ob_start() and write everything to that buffer instead of to the screen. With ob_get_clean() you get the contents of that buffer, after which the buffer is destroyed to free memory.

Check them out in the manual: [fphp]ob_start[/fphp], [fphp]ob_get_clean[/fphp]

Thanks for the help everyone.
But, I was able to get it on my own.

Thanks anyways! :smiley:

  • Eric