php整数不响应条件 答复

php整数不响应条件 答复,php,if-statement,integer,conditional,Php,If Statement,Integer,Conditional,因此,它在执行任何IF()条件之前都会进行一系列while循环。想法 问题 $i=0; $2=3; $htmlWeather=“”; ... 而($parser->parse()&&($weatherIterations>0)){ $weather迭代--; if($parser->iNodeType==NODE|TYPE|TEXT |$parser->iNodeType==NODE|TYPE|COMMENT){ if(trim($parser->iNodeValue)!=''{ //嘿,别嘲笑

因此,它在执行任何IF()条件之前都会进行一系列while循环。想法

问题
$i=0;
$2=3;
$htmlWeather=“”;
...
而($parser->parse()&&($weatherIterations>0)){
$weather迭代--;
if($parser->iNodeType==NODE|TYPE|TEXT |$parser->iNodeType==NODE|TYPE|COMMENT){
if(trim($parser->iNodeValue)!=''{
//嘿,别嘲笑那个菜鸟
交换机(一美元){
案例0:
$htmlWeather.=“title=”..$parser->iNodeValue。”
”; 打破 案例1: $htmlWeather.=“Hi=”..$parser->iNodeValue。”
”; 打破 案例2: $htmlWeather.=“Temp=”..$parser->iNodeValue。“
”; 打破 案例3: $htmlWeather.=“Lo=”..$parser->iNodeValue。”
”; 打破 案例4: $htmlWeather.=“Temp=”..$parser->iNodeValue。“
”; 打破 案例5: $htmlWeather.=“Desc=”..$parser->iNodeValue.”; 打破 }//开关
$iWorks对我来说(整数比较)。你到底是在while循环中输入的吗?也许parser->parse()返回false?@Darhazer,它进入while循环。在上面的示例代码中,$weatherIterations将值更改为2,1,0,并退出while()循环,而不执行任何if()条件(我觉得很困惑).检查$parser->iNodeType和$parser->iNodeValue@Darhazer如果我从while循环中删除“&&($weatherIterations>0)”,它会正常工作。只是我只需要运行3次,并且只得到3个最新的结果。
/* Thanks everyone :)
my guess: the while loop is running through every line of HTML code that 
has a value (class="" type="" id="" etc. – many of them are blank), but I only 
need it to count "1" if it has run through the switch up to case 5, at which 
point it grabs the last bit of the weather for a particular day.  On case 5 is 
when I need to trigger $weatherIterations-- */
$i = 0;
$weatherIterations = 3;

$htmlWeather = "";
if (empty($htmlText)) {
$htmlWeather = "<p>Weather information is not currently available.<p>";
} else {

 $parser = new HtmlParser($htmlText);

while ( $parser->parse() && ($weatherIterations > 0) ) {
    if( trim($parser->iNodeValue) != '' ) { 
        // hey, no laughing at the newbie
            switch ($i) {
                case 0:
                    $htmlWeather .= "<div id='weather'><span class='weather-title'>".$parser->iNodeValue."</span><br />";
                    break;
                case 1:
                    $htmlWeather .= "<span class='weather-hi'>".$parser->iNodeValue."<br />";
                    break;
                case 2:
                    $htmlWeather .= $parser->iNodeValue."</span><br />";
                    break;
                case 3:
                    $htmlWeather .= "<span class='weather-lo'>".$parser->iNodeValue."<br />";
                    break;
                case 4:
                    $htmlWeather .= $parser->iNodeValue."</span><br />";
                    break;
                case 5:
                    $htmlWeather .= "<span class='weather-desc'>".$parser->iNodeValue."</span></div>";
                    $weatherIterations--;
                    break;
                default:
                    $htmlWeather = "Oops! Houston, we have a problem.";
                    print $htmlWeather;
                    exit;
                } // switch
            $i<5 ? $i++: $i=0;
        } // if trim
} // while
print $htmlWeather;
} // if empty html
3
2
1
0
-1
...
-150
title= Wednesday
Hi= Hi
Temp= 29 / 85 
Lo= Lo
Temp= 24 / 76 
Desc= Sunny Periods, showers
title= Thursday
 ...
 Desc= Sunny Periods
$i = 0;
$weatherIterations = 3;
$htmlWeather = "";

   ...

while ( $parser->parse() && ($weatherIterations > 0) ) {
$weatherIterations--;
    if ($parser->iNodeType == NODE_TYPE_TEXT || $parser->iNodeType == NODE_TYPE_COMMENT) {
    if( trim($parser->iNodeValue) != '' ) { 
        // hey, no laughing at the newbie
            switch ($i) {
                case 0:
                    $htmlWeather .= "<div id='weather'><span class='weather-title'>title= ".$parser->iNodeValue."</span><br>";
                    break;
                case 1:
                    $htmlWeather .= "<span class='weather-hi'>Hi= ".$parser->iNodeValue."<br>";
                    break;
                case 2:
                    $htmlWeather .= "Temp= ".$parser->iNodeValue."</span><br>";
                    break;
                case 3:
                    $htmlWeather .= "<span class='weather-lo'>Lo= ".$parser->iNodeValue."<br>";
                    break;
                case 4:
                    $htmlWeather .= "Temp= ".$parser->iNodeValue."</span><br>";
                    break;
                case 5:
                    $htmlWeather .= "<span class='weather-desc'>Desc= ".$parser->iNodeValue."</span></div>";
                    break;
                } // switch
            $i<5 ? $i++: $i=0;

        } // if trim
        } // if parser
} // while
print $htmlWeather;