I have one .txt file and one .php file
.txt:
15118553;1315239266;0;1;EURUSD;1.4111;0;0;1315239282;1.4109;0;0;-27;0;
.php:
<?php
$text = file_get_contents('test.txt', true);
$sir = explode(";", $text);
$d=count($sir);
for($i=0; $i<=$d ; $i++)
echo "string = ". $i ."-------". $sir[$i]. "<br>" ;
?>
in localhost :
string = 0-------15118553
string = 1-------1315239266
string = 2-------0
string = 3-------1
string = 4-------EURUSD
string = 5-------1.4111
string = 6-------0
string = 7-------0
string = 8-------1315239282
string = 9-------1.4109
string = 10-------0
string = 11-------0
string = 12--------27
string = 13-------0
string = 14-------
Notice: Undefined offset: 15 in C:\xampp\htdocs\test\index.php on line 7
string = 15-------
Why do they display 15 strings? In the txt file there are only 13 strings. How do I fix this error?
forto iterate arrays. Useforeach.