Page 1 of 1

reading a TXT file into variables

Posted: Wed May 22, 2013 5:40 am
by leewad
Hi

I have the following format in a txt file

[text]EURO
1.1232
1.2836
US DOLLARS
1.4468
1.6485
AUSTRALIAN DOLLARS
1.4707
1.6913
BAHRAINIAN DINARS
0.5467
0.6283
BARBADOS DOLLARS
2.7550
3.2969
BRAZILIAN REAL
2.7477
3.4578
BRUNEI RINGGITS
1.8288
2.1017
BULGARIAN LEV
2.0866
2.5752[/text]

Im wanting read it in php and set variables to them i.e

Code: Select all

$currency = $line1;
$rate_buy= $line2;
$rate_sell= $line3;
using this for each currencies

Could anybody help me out please

Re: reading a TXT file into variables

Posted: Wed May 22, 2013 12:15 pm
by requinix
Have you tried your hand at a fopen/fgets/fclose loop? There are examples in the documentation for those functions.

Re: reading a TXT file into variables

Posted: Fri May 24, 2013 9:05 am
by litebearer
Perhaps...

Code: Select all

<?php
$lines = file("data.txt");
$x = 0;
$c = count($lines);
while($x<$c) {	
	echo "Currency: " . $lines[$x] . " -  Buy: " . $lines[$x+1] . " - Sell: " . $lines[$x+2] . "<br/>"; 
	$x = $x + 3;
}
?>
example: http://nstoia.com/sat/data.php

Re: reading a TXT file into variables

Posted: Fri May 24, 2013 9:12 am
by leewad
Thanks a lot will give it a go :-)