So essentially I'm opening a large file (I think it's large - 19MB) and trying to comb out anything that's not a 4 letter .com and dropping from the registry on todays date. So what I am trying to do below is call out the file and for each line in it find strings with date in line and 35 or less in characters (prior to stripping chars).
Then I want it to check that it's a .com has no didgets and does not contain a hyphen.
What am I missing?
<?php
date_default_timezone_set('UTC');
$extension = '.com';
$lines = file('PoolDeletingDomainsList.txt');
//$lines = file('testdomains.txt');
$date = date('n/j/Y');
echo "<b>4 Letter premiums for ". $date .":</b><br />";
foreach($lines as $line)
if ((false !== strpos($line,$date)) && (35 <= strlen($line))) {
$line = preg_replace('/12:00:00 AM,AUC\b/','<br />', $line);
$line = preg_replace('/,9\/28\/2013/', '', $line);
if ((false !== strpos($line, $extension)) && (0 === preg_match('#\d#',$line)) && (0 === preg_match('/-/', $line))){
echo $line;
}
}
?>
Try (35 >= strlen($line)
rather than (35 <= strlen($line)
if you want lines 35 chars or less. Personally, I prefer to order comparisons like that the other way around, e.g. strlen($line) <= 35
, which I think is more readable and avoids mistakes like the one you just made :)