debugging - Please help me fix this PHP while statement -
the script below supposed end when "best match" found in string, though know found script keeps on running. please me fix error.
$end = "1"; while ($end != 2) { foreach($anchors $a) { $i = $i + 1; $text = $a->nodevalue; $href = $a->getattribute('href'); //if ($i<80) { //if (strpos($item, ".$array.") == false) { //} if (strpos($text, "best match") == true) { $end = "2"; } if (strpos($text, "by owner") === false) { if (strpos($text, "map") === false) { if ($i > 17) { echo "<a href =' ".$href." '>".$text."</a><br/>"; } } } } //$str = file_get_contents($href); //$result = (substr_count(strip_tags($str),"ipod")); //echo ($result); }
in strpos
, you're comparing true, , wrong.
also, in thas if statement should break foreach , while loop.
this right code:
<?php while ($end != 2) { foreach($anchors $a) { $text = $a->nodevalue; $href = $a->getattribute('href'); if (strpos($text, "best match") !== false) { $end = "2"; break 2; } if (strpos($text, "by owner") === false) { if (strpos($text, "map") === false) { if ($i > 17) { echo "<a href =' ".$href." '>".$text."</a><br/>"; } } } } }
Comments
Post a Comment