【发布时间】:2016-12-04 17:10:20
【问题描述】:
此代码用于读取包含 100 个 url 的文本文件的内容,每行一个。该脚本是使用 file_get_contents 在 url 中搜索特定单词。
<?php
$mysearch = file("phpelist.txt");
for($index = 0; $index <count($mysearch); $index++)
{ while ($index >=10 && $index <=20 ):
$mysearch[$index] = str_replace("\n", "", $mysearch[$index]);
$data = file_get_contents("$mysearch[$index]");
$searchTerm = 'about';
if (stripos($data, $searchTerm) !== false) {
echo "$mysearch[$index]</strong>...FOUND WORD<br><strong>";
}
else
{
echo "$mysearch[$index]</strong>...NO SUCH WORD<br><strong>";
}
endwhile;
}
?>
【问题讨论】:
-
$index在while内部没有修改,一旦进入就永远不会退出 -
你确定这段代码可以运行吗?看起来你那里有语法错误......使用
endwhile时,你应该使用while(...) : -
并阅读其他评论:)
-
也许您想要的是
if而不是while?无论如何,语法是错误的,就像上面提到的那样 - php.net/manual/en/control-structures.while.php -
嗨,我将 while 更改为 if 并显示所有网址。我需要 10 到 20 之间的行。
标签: php while-loop