dsqe46004 2019-07-23 17:36
浏览 138
已采纳

count():参数必须是实现Countable的数组或对象

I'm getting this warning on my website, im just getting the information is it IP available or not, it's work, its says it's unavailable but it shows an warning also about code, I searched about it, but none of those answers didn't help me. So the code is working, just want to get off this warning. Php 7.x doesn't support syntax like this? The problem is in if (count($test)==1).

$printers = file("printers.txt"); //input txt file with IP addresses in chosen order
    $number_of_printers = count ($printers);
    for ( $i = 0 ; $i < $number_of_printers ; $i++)
    {
    $ip=str_replace("
","",$printers[$i]);
    $ip=str_replace("","",$ip);
    $ip=str_replace("
","",$ip);
    $test=@get_headers("http://$ip");
    if (count($test)==1){

        //do stuff here
        echo "<div class='printerwrapper'<div class='location'>$ip is unavailable</div></div>";
        continue;
    }
  • 写回答

2条回答 默认 最新

  • doumiebiao6827 2019-07-23 17:46
    关注

    When get_headers() fails it returns false and count(false) triggers that warning since PHP/7.2 (demo). The rationale is that counting a boolean false and getting 1 doesn't make much sense.

    Perhaps you just want this:

    if (!$test) {
        //do stuff here
        echo "<div class='printerwrapper'<div class='location'>$ip is unavailable</div></div>";
        continue;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题