循环PHP检查,直到找到网页中的文本

循环PHP检查,直到找到网页中的文本,php,file,loops,while-loop,find,Php,File,Loops,While Loop,Find,按下submit按钮时,我希望PHP代码检查另一个网站的网页中是否存在字符串 $random = rand(100,1000); strpos(file_get_contents('website.com/url.php?username='.$username), $random); 因此,在代码找到$random的值之前,它不会继续处理脚本的其余部分。更新大约需要10秒钟 我尝试了一段时间的脚本: $random = rand(100,1000); echo '<div data-a

按下submit按钮时,我希望PHP代码检查另一个网站的网页中是否存在字符串

$random = rand(100,1000);
strpos(file_get_contents('website.com/url.php?username='.$username), $random);
因此,在代码找到$random的值之前,它不会继续处理脚本的其余部分。更新大约需要10秒钟

我尝试了一段时间的脚本:

$random = rand(100,1000);
echo '<div data-alert class="alert-box alert">'.$random.'</div>';
$key = false;

while($key){    
if(strpos(file_get_contents('website.com/url.php?username='.$username), $random)) $key = true;
}
$random=rand(1001000);
回音“.$random.”;
$key=false;
而($key){
if(strpos(file_get_contents('website.com/url.php?username='.$username),$random))$key=true;
}
这似乎不起作用

按下submit按钮时,我希望PHP代码检查另一个网站的网页中是否存在字符串

$random = rand(100,1000);
strpos(file_get_contents('website.com/url.php?username='.$username), $random);
如果我正确理解了您的问题,请尝试以下方法:

$content = file_get_contents($url);
if(str_replace($string, "", $content) != $content)
    echo "found";
编辑:

编辑2:

$i = 0;
do {
    $content = file_get_contents($url);
    $i++;
} while(strpos($content, $string) === false && $i <= 100);
$i=0;
做{
$content=file\u get\u contents($url);
$i++;
}while(strpos($content,$string)==false&&$i30){
呼应“没有发现”;
}

文件获取内容('http://website.com
这需要一个完整的http调用。是的,我知道,我只是快速更改了发布的URL。:)所以。。。你怎么回事啊?php进入超时状态?请看,您可能想在这些http请求之间休眠()一两秒钟。@Ulver执行的自然流就是这样做的,所以它是多余的!!
$i = 0;
do {
    $content = file_get_contents($url);
    $i++;
} while(strpos($content, $string) === false && $i <= 100);

if($i > 100){
    echo "nothing found";
}
$startTime = time();
do {
    $content = file_get_contents($url);
} while(strpos($content, $string) === false && time() - $startTime < 30);

if(time() - $startTime > 30){
    echo "nothing found";
}