0

im using a simple function to read my txt file

my txt file content will be like this :

album= Prisoner
info= Description about this singer 

and php code :

$Path = 'dewp/pix/info.txt';
$product = parse_ini_file($path);
echo $product['album'];
echo $product['info'];

everything is fine and works good on localhost , but not in my website ,

in my website it only shows $product['info'] and cant show $product['album']

this is really mad , why it cant show only album !

is there any other approch to get these two element from a txt file !?

Mac Taylor
  • 5,020
  • 14
  • 50
  • 73
  • 1
    What does a `print_r($product)` say? – Pekka Jul 04 '10 at 16:04
  • if you cannot get it to work and it does not have to be a Ini file, [consider using CSV, XML, YAML or even plan arrays as a file format](http://stackoverflow.com/questions/2237291/php-reading-file/2237315). – Gordon Jul 05 '10 at 06:16

2 Answers2

0

Change your .ini to look like this:

album = "Prisoner"
info = "Description about this singer"

Alternatively, you can parse it yourself:

$string = file_get_contents('dewp/pix/info.txt');
$data = explode("\n", $string);

foreach($data as $value) {
  $dataPair = explode("=", $value);

  $$dataPair[0] = $dataPair[1];
}

echo $album;
echo $info;

Hopefully that fixes it.

xil3
  • 16,305
  • 8
  • 63
  • 97
  • again it only works on localhost not the website ! i think something is wrong with php.ini setting is there another approach such exploding the txt file into an arrays ?! – Mac Taylor Jul 04 '10 at 15:51
  • 1
    You can replace `file_get_contents` and `explode` with a single call to `file`. – casablanca Jul 04 '10 at 16:09
0

Maybe one side uses crlf for line termination, and the other only lf. This can cause the whole file being seen as one line. This in turn can cause only the first element to be seen.