Jump to content

extracting some digits in a medium long string [with mechanize[


dilbertone

Recommended Posts

hi there - hello dear PHP-Friends,

 

good evening!  - i want to extract some data ouf of a large html-file.

 

i have - a very very large amount of data:  approx 5000 x the following line-sheme!:

 

 

67003 Cato Bontjes Vice Versum House 1 28832 Achim 

62042 Cato Bontjes Vice Versum House 2 28832 Achim

41798 Cato Bontjes Vice Versum House 3 37139 Adelebsen

40034 Cato Bontjes Vice Versum House 4 21365 Adendorf

46218 Cato Bontjes Vice Versum House 5 31855 Aerzen

42481Cato Bontjes Vice Versum House 6  21702 Ahlerstedt

49761 Cato Bontjes Vice Versum House 7 26197 Ahlhorn

 

 

Question: how can i  extract the first 5 first digits...!?

 

I have allready some solutions here -

 

 

i need a very very robuste solution 

 

diblertone1

Not tested, but should work:

 

$lines = file('/path/to/file.html');
foreach($lines as &$line) {
   $values = explode(' ', $line);
   $line = $values[0];
}
print_r($lines);

 

Or this:

 

preg_match_all('/^[\d]{5}/m', file_get_contents('/path/to/file.html'), $matches);
print_r($matches[]0]);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.