开发者

problem in using parse_ini_file to get vars from a txt file

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜