You are here:  » Get last record from a tab delimited file from url

Get last record from a tab delimited file from url

Submitted by jp_solspot on Wed, 2013-01-02 17:15 in


I am trying to get the data contained in the last row from the following url/network location:

{link saved}

would like to be able to load/insert the data into a db table

example data from file:
201301021605 280 271 267 272 280 280 267 266 264 311

for some reason when attempting to use the demo on site it fails to load the data as well. could it be because of the ampersands in the url?

thanks so much for a great product!


Submitted by support on Thu, 2013-01-03 10:24

Hi JP,

The file appears to be fixed width delimited which isn't a format supported by Magic Parser, however it would be straight forward to get the last line using basic string handling functions - have a go with something like:

file_get_contents("{link saved}");
// trim to remove any blank lines at the end
$data trim($data);
// explode to split into lines
$lines explode("\n",$data);
// get last line using count()
$last_line $lines[count($lines)-1];
// use preg_replace to change spaces into tab
$last_line preg_replace('/[ ]{2,}/',"\t",$last_line);
// finally explode on tab to get individual fields
$fields explode("\t",$last_line);

(replace {link saved} with your source URL)

Hope this helps!