PDA

View Full Version : Please help me figuring this out.



WetCode
21 Nov 2010, 11:53 AM
Its been some time since i coded somthing in PHP so i need some help here.

I want to search a .txt or .rtf file for a line with random numbers.
I have got some help and came up white this.



<?php
// the file has been uploaded.
// (do it yourself)
$file = 'file.rtf';
// 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);
}

?>


What this SHOULD do is to basically find the lines in the file with random numbers and it should display the lines that matches. tested and it comes up showing nothing. (Dont know if the code is writen correct.)
Thanks to all that can shed some lights on this.

PS: Also i`am sorry if my grammera is not all good. I got some problems with spelling and this is not my native tongue.