file_get_contents() returns incomplete data
Posted: Mon May 18, 2009 12:32 pm
Hi,
I'm just learning to work with file contents in PHP and I'm having some trouble with file_get_contents. It doesn't return the entire contents of the (very simple) file.
When trying to get this file:
This code:
Returns this (in html output):
file_get_contents: array('type' => 'Ground, 250g', 'price' => 495, 'weight' => 250, 'frv' => 3, 'category' => 'standard'), 1 => array('type' => 'Whole Bean, 250g', 'price' => 595, 'weight' => 250, 'frv' => 3, 'category' => 'limited', 'limit' => 4), 2 => array('type' => 'Free Sample, 100g', 'price' => 0, 'weight' => 100, 'frv' => 3, 'category' => 'sample')); ?>
When I use file() instead, it does manage to get all the lines, but I want to use file_get_contents() and, more importantly, I want to know WHY this isn't working. If I change the filetype to .txt it gets the entire contents, but I thought it was supposed to be possible to get .php files. I want to be able to work with files ending in .php so I can also use it as an include file.
Please let me know if there's any more information I can give you. This really has me stumped and I'd appreciate any help.
I'm just learning to work with file contents in PHP and I'm having some trouble with file_get_contents. It doesn't return the entire contents of the (very simple) file.
When trying to get this file:
Code: Select all
<?php
$productName = 'Sample Product 1';
$types = array(0 => array('type' => 'Ground, 250g',
'price' => 495,
'weight' => 250,
'frv' => 3,
'category' => 'standard'),
1 => array('type' => 'Whole Bean, 250g',
'price' => 595,
'weight' => 250,
'frv' => 3,
'category' => 'limited',
'limit' => 4),
2 => array('type' => 'Free Sample, 100g',
'price' => 0,
'weight' => 100,
'frv' => 3,
'category' => 'sample'));
?>
Code: Select all
$filetxt =file_get_contents("products/sample_product.php");
echo "file_get_contents: " . $filetxt;
file_get_contents: array('type' => 'Ground, 250g', 'price' => 495, 'weight' => 250, 'frv' => 3, 'category' => 'standard'), 1 => array('type' => 'Whole Bean, 250g', 'price' => 595, 'weight' => 250, 'frv' => 3, 'category' => 'limited', 'limit' => 4), 2 => array('type' => 'Free Sample, 100g', 'price' => 0, 'weight' => 100, 'frv' => 3, 'category' => 'sample')); ?>
When I use file() instead, it does manage to get all the lines, but I want to use file_get_contents() and, more importantly, I want to know WHY this isn't working. If I change the filetype to .txt it gets the entire contents, but I thought it was supposed to be possible to get .php files. I want to be able to work with files ending in .php so I can also use it as an include file.
Please let me know if there's any more information I can give you. This really has me stumped and I'd appreciate any help.