简体   繁体   中英

Loop PHP check until text within webpage has been found

On pressing the submit button, I want the PHP code to check to see if a string exists within a webpage on another website.

$random = rand(100,1000);
strpos(file_get_contents('website.com/url.php?username='.$username), $random);

So, until the code has managed to find the value of $random, it won't continue with the rest of the script. The updates can take about 10 seconds.

I have tried a while script:

$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;
}

This doesn't seem to work.

On pressing the submit button, I want the PHP code to check to see if a string exists within a webpage on another website.

If I understood your question correctly, try this:

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

EDIT:

do {
    $content = file_get_contents($url);
} while(strpos($content, $string) === false);

EDIT 2:

$i = 0;
do {
    $content = file_get_contents($url);
    $i++;
} while(strpos($content, $string) === false && $i <= 100);

EDIT 3:

$i = 0;
do {
    $content = file_get_contents($url);
    $i++;
} while(strpos($content, $string) === false && $i <= 100);

if($i > 100){
    echo "nothing found";
}

EDIT 4:

$startTime = time();
do {
    $content = file_get_contents($url);
} while(strpos($content, $string) === false && time() - $startTime < 30);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM