douyinzha5820 2013-09-28 18:47
浏览 31

我究竟做错了什么? strpos,strlen和preg_match

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;
}
}
?>
  • 写回答

1条回答 默认 最新

  • dqb77047 2013-09-28 18:57
    关注

    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 :)

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败