tags:

views:

28

answers:

2

hey guys 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 !?

A: 

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
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
I just updated my post for you with an additional answer.
xil3
You can replace `file_get_contents` and `explode` with a single call to `file`.
casablanca
A: 

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.