Here's my problem. I am reading from a text file using this:
if (!file_exists($ file))
{
echo "Don't exist\n";
return false;
}
$fd = @fopen($file, 'r');
if (!is_resource($ fd))
{
echo "Error reading\n";
return false;
}
And it works fine. The data that will be read will always be in the text
file in the form of
one - two - three - alpha beta kappa delta epsilon 13.5pp 29.95eu
Now I want to explode that array that was read so I use this:
$arrayData = explode("-", fgets($fd, 4096));
print "first=$arrayDa ta[0]\n";
print "second=$arrayD ata[1]\n";
print "third=$arrayDa ta[2]\n";
print "fourth=$arrayD ata[3]\n";
which will give me
first=one second=two third=three fourth=alpha beta kappa delta epsilon
13.5pp 29.95eu
But I need to access the last two items (13.5pp and 29.95eu) of this
array to split them off as well so that the final output I need would be
like this:
first=one second=two third=three fourth=alpha beta kappa delta
epsilon.txt numpages=13.5pp cost=29.95eu
How can I do that? Do I need to further explode $arrayData[3] using a
space delimiter? Is there a way to grab the last two fields only because
the length of the 'alpha beta kappa delta epsilon' will not always be
the same but the numpages and cost will always be the last two elements
in the array. Any help would be appreciated.
if (!file_exists($ file))
{
echo "Don't exist\n";
return false;
}
$fd = @fopen($file, 'r');
if (!is_resource($ fd))
{
echo "Error reading\n";
return false;
}
And it works fine. The data that will be read will always be in the text
file in the form of
one - two - three - alpha beta kappa delta epsilon 13.5pp 29.95eu
Now I want to explode that array that was read so I use this:
$arrayData = explode("-", fgets($fd, 4096));
print "first=$arrayDa ta[0]\n";
print "second=$arrayD ata[1]\n";
print "third=$arrayDa ta[2]\n";
print "fourth=$arrayD ata[3]\n";
which will give me
first=one second=two third=three fourth=alpha beta kappa delta epsilon
13.5pp 29.95eu
But I need to access the last two items (13.5pp and 29.95eu) of this
array to split them off as well so that the final output I need would be
like this:
first=one second=two third=three fourth=alpha beta kappa delta
epsilon.txt numpages=13.5pp cost=29.95eu
How can I do that? Do I need to further explode $arrayData[3] using a
space delimiter? Is there a way to grab the last two fields only because
the length of the 'alpha beta kappa delta epsilon' will not always be
the same but the numpages and cost will always be the last two elements
in the array. Any help would be appreciated.
Comment