Help Random Numbers in a .txt or .rtf
Posted: Sun Nov 21, 2010 12:48 pm
Can some one help me cant get this to work.
Trying to make a script that finds all the lines in a .txt or .rtf that contains a line of numbers that has 4 ore more numbers like 1234 on Line: 5 and 12345 on line: 16
This is the code i`am using dont know if its all corect.
<?php
// the file has been uploaded.
// (do it yourself)
$file = 'file.txt';
// the minimum length of each number
$min = 4;
$matches = array ();
foreach (file ($file) as $k => $line)
{
if (preg_match ('/^[\d]{' . $min . ',}+$/', $line))
{
$matches[] = $k;
}
}
if (sizeof ($matches))
{
// dumps line numbers with positive match
print_r ($matches);
}
?>
Thanks to all that can help.
Trying to make a script that finds all the lines in a .txt or .rtf that contains a line of numbers that has 4 ore more numbers like 1234 on Line: 5 and 12345 on line: 16
This is the code i`am using dont know if its all corect.
<?php
// the file has been uploaded.
// (do it yourself)
$file = 'file.txt';
// the minimum length of each number
$min = 4;
$matches = array ();
foreach (file ($file) as $k => $line)
{
if (preg_match ('/^[\d]{' . $min . ',}+$/', $line))
{
$matches[] = $k;
}
}
if (sizeof ($matches))
{
// dumps line numbers with positive match
print_r ($matches);
}
?>
Thanks to all that can help.