php script why if else not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Are

    php script why if else not working

    this script gives the result below when ping is good, a numerical value i think in the form of a string
    Code:
    <?php
    function pinger ($serverIP)
    {
    	$pingReturn = exec ('ping ' .$serverIP );
    	return $pingReturn ;
    	
    }
    $tmp1 = explode(',' , pinger("localhost"));
    echo "$tmp1[2] \n";
    $newstring=substr($tmp1[2],10);
    echo "$newstring \n";
    $finalstr=substr_replace($newstring ,"",-2);
    echo $finalstr;
    ?>

    Average = 0ms
    0ms
    0 is $fianlstr


    when ping is bad --- $finalstr is (100% los ------- yes exactly this (100% los

    later in the script i have an if elseif statements
    Code:
    if ($finalstrng <= 50) {$status = "good";}
    				elseif ($finalstrng > 50 && $finalstrng <= 100){$status = "congested";}
    				else {$status = "bad";}
    but when $finalstrng is (100% los the status still says good

    Please help need to get $finalstrng say bad when not a numeric value
    Thanks
    Last edited by Dormilich; Oct 5 '10, 01:11 PM. Reason: please use [code] [/code] tags when posting code
  • paulrajj
    New Member
    • Sep 2008
    • 47

    #2
    I think you might have a problem with the variables in your script.

    change the variable $finalstrng to $finalstr

    Comment

    • ziycon
      Contributor
      • Sep 2008
      • 384

      #3
      It looks like the value is always 0 which would make it always 'good', like paulrajj said, check your variable names and that your using the correct one.

      Comment

      Working...