krygnc Posted June 19 Share Posted June 19 Hello, I am pulling data from a site I want to give color according to the value that I want to do, is this possible? I am doing it with the code below but the result is always green $url = "simple"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($curl); curl_close($curl); $dom = new DOMDocument(); @$dom->loadHTML($data); $xpath = new DOMXPath($dom); $statu1 = $xpath->query('//*[@id="page-wrapper"]/div/div[6]/div/h4[7]/span'); foreach ($statu1 as $status1) if ($statu1 = "Online") { echo "<font color = green>$status1->nodeValue</font><br>"; } elseif ($statu1 = "Offline") { echo "<font color = red>$status1->nodeValue</font><br>"; } Quote Link to comment https://forums.phpfreaks.com/topic/328906-color-by-conditional-value/ Share on other sites More sharing options...
requinix Posted June 19 Share Posted June 19 if ($statu1 = "Online") { echo "<font color = green>$status1->nodeValue</font><br>"; } elseif ($statu1 = "Offline") { echo "<font color = red>$status1->nodeValue</font><br>"; } One = does an assignment, which means the above code actually works like $statu1 = "Online"; if ($statu1) { echo "<font color = green>$status1->nodeValue</font><br>"; So naturally, every status will be green. Two ==s does equality comparison. (Three ===s is if you want to be pedantic about what it means to be "equal".) if ($statu1 == "Online") { echo "<font color = green>$status1->nodeValue</font><br>"; } elseif ($statu1 == "Offline") { echo "<font color = red>$status1->nodeValue</font><br>"; } That aside, this is very outdated HTML 4-style markup. You should switch to <span>s and CSS. Quote Link to comment https://forums.phpfreaks.com/topic/328906-color-by-conditional-value/#findComment-1655284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.