You are here: Re: Sorting Massive amounts of Data « PHP Programming Language « IT news, forums, messages
Re: Sorting Massive amounts of Data

Posted by malatestapunk on 11/16/06 07:47

Or you could do something like:

$matches = array();
$fileText = file_get_contents('data.txt'); // PHP4.3+
if (preg_match_all ('/^.{9}(SUBPATTERN_THAT_MATCHES_YOUR_DATA).*$/m',
$fileText, $matches)) {
// $matches now contains your data, in this format:
// $matches[0][0] - the whole first matched line
// $matches[0][1] - your data from the first matched line
// $matches[1][0] - the whole second matched line
// $matches[1][1] - your data from the second matched line
// ... and so on.
} else {
// Your search failed - nothing matched.
}

Note that you'll have to replace SUBPATTERN_THAT_MATCHES_YOUR_DATA with
a valid regular expression describing the data you'd like to extract.

lorento wrote:
> Advo wrote:
>
> >
> > MNs73dd78INFORMATION I NEED 32427 12759 39384425 495242 15.206412
> > 0.191214 44.164503 -93.993798
> >
> > As you can see, its pretty messed up. I only need the "INFORMATION I
> > NEED" part, not the 9 characters before, nor any numbers or decimal
> > places afterwards.
> >
>
> You can use regex maybe like this (not tested yet):
>
> <?php
>
> $fr = fopen ("data.txt", "r");
> $fw = fopen ("data_clean.txt", "a");
>
> while (!feof($fr))
> {
> $ln = fgets($fr, 1024);
> $ln = preg_replace ("/^(\w{9})(.*)(\d+)/", "$2", $ln);
> fwrite($fw, $ln);
> }
> fclose($fr);
> fclose($fw);
>
> ?>
>
> --
> http://www.mastervb.net
> http://www.theaussiemap.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация