循环PHP检查直到找到网页内的文本
Loop PHP check until text within webpage has been found
按下提交按钮后,我希望 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;
}
这似乎行不通。
On pressing the submit button, I want the PHP code to check to see if a string exists within a webpage on another website.
如果我理解正确你的问题,试试这个:
$content = file_get_contents($url);
if(str_replace($string, "", $content) != $content)
echo "found";
编辑:
do {
$content = file_get_contents($url);
} while(strpos($content, $string) === false);
编辑 2:
$i = 0;
do {
$content = file_get_contents($url);
$i++;
} while(strpos($content, $string) === false && $i <= 100);
编辑 3:
$i = 0;
do {
$content = file_get_contents($url);
$i++;
} while(strpos($content, $string) === false && $i <= 100);
if($i > 100){
echo "nothing found";
}
编辑 4:
$startTime = time();
do {
$content = file_get_contents($url);
} while(strpos($content, $string) === false && time() - $startTime < 30);
if(time() - $startTime > 30){
echo "nothing found";
}
按下提交按钮后,我希望 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;
}
这似乎行不通。
On pressing the submit button, I want the PHP code to check to see if a string exists within a webpage on another website.
如果我理解正确你的问题,试试这个:
$content = file_get_contents($url);
if(str_replace($string, "", $content) != $content)
echo "found";
编辑:
do {
$content = file_get_contents($url);
} while(strpos($content, $string) === false);
编辑 2:
$i = 0;
do {
$content = file_get_contents($url);
$i++;
} while(strpos($content, $string) === false && $i <= 100);
编辑 3:
$i = 0;
do {
$content = file_get_contents($url);
$i++;
} while(strpos($content, $string) === false && $i <= 100);
if($i > 100){
echo "nothing found";
}
编辑 4:
$startTime = time();
do {
$content = file_get_contents($url);
} while(strpos($content, $string) === false && time() - $startTime < 30);
if(time() - $startTime > 30){
echo "nothing found";
}