doulianqi3870 2015-06-27 00:14
浏览 49
已采纳

PHP IF语句和循环

I have this php code:

<?php
if(isset($_POST['gen'])){              

$genapi = "http://domain.com/api.php";
$result5 = htmlentities(file_get_contents($genapi));

list($first, $last) = explode(':', $result5);

header('Location: minecraft.php?line='.$result5);

}
?>

I am having trouble making it so if "$result5" returns with "no" then to wait 2 seconds then try again but if "$result5" does NOT return with "no" it will run the header line.

  • 写回答

1条回答 默认 最新

  • dongreng9864 2015-06-27 00:17
    关注
    if(isset($_POST['gen'])){ 
    
    $loop = true;
    
      while($loop){
        $genapi = "http://domain.com/api.php";
        $result5 = htmlentities(file_get_contents($genapi));
    
        if($result5 !== 'no'){ // check your $result5 based on the value it returns
           $loop = false;
           list($first, $last) = explode(':', $result5);
           header('Location: minecraft.php?line='.$result5);
        }
        else{
          sleep(2);
        }
    
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部