I have the following code which is suppose to loop through a set of nodeValues and stop on the node if it begins with specific letters. I am very new to looping but thought the following code would work.. what am i doing wrong?
$file = $DOCUMENT_ROOT. "http://website.com";
$doc = new DOMDocument();
@$doc->loadHTMLFile($file);
$elements = $doc->getElementsByTagName('td');
$i=0;
while (trim(substr($elements->item($i)->nodeValue, 0, 3)) !== "MON" | "TUE"){
echo $elements->item($i)->nodeValue;
$i=$i+1;
};
You have some significant logic and operator issues in your
whilecondition.|is a bitwise OR comparison, and it looks like you really mean to use a logical AND&&, since your loop needs to continue as long as the node value is not equal to either MON or TUE:I would recommend storing the nodeValue outside the while loop and comparing a variable for readability: