Jump to content

Texan78

Members
  • Posts

    272
  • Joined

  • Last visited

Everything posted by Texan78

  1. Here is the main code that I am using that might make it easier to understand and might make it easier to explain. From the code below, I need to calculate $LRH_bankfull & $LRH_current which it does now to which gives me the difference, LRH_calcLevel($LRH_current, $LRH_bankfull); I need it to take the output from LRH_calcLevel and calculate it with $LRH_totalDepth to give me the difference and create a new output from that calculation to give me a new variable that I can display. So LRH_calcLevel +/- $LRH_totalDepth = $LRH_actualCurrent //Parse Lake Ray Hubbard XML Data $site = simplexml_load_file($LRH_data);{ $LRH_bankfull = '435.5'; $LRH_totalDepth = '40'; $LRH_current = $site->observed->datum[0]->primary; $LRH_vaild = $site->observed->datum[0]->valid; $LRH_updated = DATE("D, M d, g:i a", STRTOTIME($LRH_vaild)); } //Lets calculate the lake depatures from full pool for Lake Ray Hubbard function LRH_calcLevel($LRH_current, $LRH_bankfull) { //Get float values from strings $LRH_current = floatval($LRH_current); $LRH_bankfull = floatval($LRH_bankfull); //Calculate the difference $LRH_calcLevel = $LRH_current - $LRH_bankfull; //Format difference to two decimal places and add 'Ft' $LRH_calcLevelStr = (string) number_format($LRH_calcLevel, 2) . ' Ft'; //If vlaue is positive add a + to beginning if($LRH_calcLevel>0) { $LRH_calcLevelStr = '+'.$LRH_calcLevelStr; } //Return the calculated formatted value return $LRH_calcLevelStr; } ////Lets calculate the lake percentage from full pool for Lake Ray Hubbard $val1 = $LRH_current; $val2 = $LRH_bankfull; $LRH_prec = ( $val1 / $val2) * 100; // 1 digit after the decimal point $LRH_prec = round($LRH_prec, 1);
  2. Hello, forgive me if I didn't title this properly. I will try to make this short and sweet and explain it the best I can. I have a script I wrote that uses SimpleXML to parse data and that part works fine. Only problem is the data is kind of construed from the XML feed and I need to convert it to a more real world calculation. The script parses XML for lake level data. The problem is it returns conservation pool levels. The problem with that is lakes are not 400+ feet deep. As it is set up now the XML contains full pool and the current level. From that I display the full pool and the current levels. It then takes the full pool minus the current level to create two new variables, departure I.E. how low or high it is over full pool, then also create % full. The calculations are fine but, since it is basing it off conservation pool I need to translate this to display it in a more known way. What I am wanting to do is hard set the variable for full pool for the actual lake depth. I still need to use the full pool variable to calculate the rest even though I won't be showing that data. So full pool - minus current level to create the departure as it does. Then take the departure variable that was created and subtract/add it from the hard set lake depth to give me the actual new depth of the lake. I.E. $a +/- $b = $c then $c +/- $d = $e I hope this makes sense. What I am trying to do is really simple. I am just not good at really explaining things and trying to comprehend how this needs to be laid out and the logic for it. If you need more info or the code I am working with please let me know. So how could I go about doing this? -Thanks
  3. Thank you so much for you help and jarring my dead brain. Here is what I ended up doing once I realized what you were saying. The value of $noStormMessage = There are currently no active watches, warnings or advisories. Which is what is produced from the XML $summary variable. Which when styled looks like this below. This is what I ended up doing with your help. Since $noStormMessage is just a variable with data. I created a table around it to display where I wanted it. Since you suggested the if/else statement that made sense and what I was looking to do. Thanks again for all your help! // If no storms were in the source, set no storm message if($error) { $tData .= " <tr><td style='{$td1Style}; text-align:center;'>NWS WATCHES/WARNINGS/ADVISORIES</td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td5Style}'>{$noStormMessage}</td>\n"; $tData .= " </tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; } else { $tData .= " <tr><td style='{$td1Style};'><b>{$event}</b> <div style='float:right'><b>Updated: {$Updated}</b></div></td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'>Effective: <b>{$effectiveDate}</b> - Expires: <b>{$expiresDate}</b> - Status: <b>{$status}</b> - Severity: <b>{$severity}</b> - Urgency: <b>{$urgency}</b></td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'>Issued For: <b>{$area}</b></td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'><strong>Summary:</strong> {$Summary}</td></tr>\n"; } $tData .= "</tbody>\n"; $tData .= "</table>\n"; $tData .= $afterTable; endforeach; endif; echo $tData;
  4. There is, that is what $tData is. // Let's assign the table some styles $tableStyle = "width: 100%; margin:0px auto; background-color:{$bkgColor};"; $td1Style = "{$tbrdr};{$sbrdr}; padding:2px 0px 2px 6px; background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};"; $td2Style = "{$sbrdr}; padding:6px 0px 0px 6px; background-color:{$alertColor};"; $td3Style = "{$sbrdr}; line-height:5px; background-color:{$alertColor};"; $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$alertColor};"; // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'><b>{$event}</b> <div style='float:right'><b>Updated: {$Updated}</b></div></td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'>Effective: <b>{$effectiveDate}</b> - Expires: <b>{$expiresDate}</b> - Status: <b>{$status}</b> - Severity: <b>{$severity}</b> - Urgency: <b>{$urgency}</b></td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'>Issued For: <b>{$area}</b></td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'><strong>Summary:</strong> {$Summary}</td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; $tData .= $afterTable; endforeach; endif; //If no storms were in the source, set no storm message if(!$tData) { $tData = $noStormMessage; } echo $tData;
  5. Thank you, that appears to work, but there is no style assigned to it. Since Updated and Summary will never be empty from the XML is it possible to check different variables and if those are empty them show my normal styled no storm message? I tried playing around with exchanging it with empty variables but it threw undefined error for summary and updated. Is that because those are the entry points and I was using childs to check maybe? -Thanks
  6. Hello, I am sorry for this question in advance. I will try to explain it as detailed but, as short as possible so bare with me. I have a script that I did that parses an XML file and outputs the info in a table. The tables are created with each entry in XML file. Everything works great and as designed except for when there is no data. I know why it is doing this, I am just not sure how to approach fixing this. So here is what the data looks like where there is nothing and what the table shows. I am posting a screenshot of the XML file as I am not sure it will be empty if I post the link. Here is what it is suppose to look like taken from another script using the same method. Now this is happening because summary any some of the variables from the XML in the php isn't empty, so it is producing the table with broken data that doesn't exist because it thinks that XML has data in it because of how the XML is construct, it really isn't empty. So is there a way I can check one of the variables that if it is empty then show the noStormMessage table instead of the table that thinks there is data when there really isn't? I hope I explained this good enough. If not forgive me and I will try to explain it or answer any questions you might have. Here is the code I am working with for that script, just the relevant logic, not the styling and settings that is above this part. //Set initial output to false $tData = false; $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); foreach ($result as $entry): $updated = $entry->updated; $Updated = date("D, M d, g:i a", strtotime($updated)); $summary = $entry->summary; // Replaces all triple periods with single periods $summary = trim(str_replace('...', '.', $summary), '.') . '.'; //now capitalize every letter after a . ? and ! followed by space $Summary = preg_replace_callback('/([.!?*])\s*(\w)/', function ($matches) { return strtoupper($matches[1] . ' ' . $matches[2]); }, ucfirst(strtolower($summary))); $event = $entry->children("cap", true)->event; $effective = $entry->children("cap", true)->effective; $expires = $entry->children("cap", true)->expires; $updated = $entry->children("cap", true)->updated; $updateDate = date("D, M d, g:i a", strtotime($updated)); $effectiveDate = date("D, M d, g:i a", strtotime($effective)); $expiresDate = date("D, M d, g:i a", strtotime($expires)); $status = $entry->children("cap", true)->status; $severity = $entry->children("cap", true)->severity; $urgency = $entry->children("cap", true)->urgency; $area = $entry->children("cap", true)->areaDesc; include ('inc-alert-colors.php'); // Let's assign the table some styles $tableStyle = "width: 100%; margin:0px auto; background-color:{$bkgColor};"; $td1Style = "{$tbrdr};{$sbrdr}; padding:2px 0px 2px 6px; background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};"; $td2Style = "{$sbrdr}; padding:6px 0px 0px 6px; background-color:{$alertColor};"; $td3Style = "{$sbrdr}; line-height:5px; background-color:{$alertColor};"; $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$alertColor};"; // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'><b>{$event}</b> <div style='float:right'><b>Updated: {$Updated}</b></div></td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'>Effective: <b>{$effectiveDate}</b> - Expires: <b>{$expiresDate}</b> - Status: <b>{$status}</b> - Severity: <b>{$severity}</b> - Urgency: <b>{$urgency}</b></td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'>Issued For: <b>{$area}</b></td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'><strong>Summary:</strong> {$Summary}</td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; $tData .= $afterTable; endforeach; endif; //If no storms were in the source, set no storm message if(!$tData) { $tData = $noStormMessage; } echo $tData; ?> -Thanks!
  7. Disregard, I am an idiot and got it sorted. Changed this.... if ($_REQUEST['mode'] == 'expired') To this.... if (isset($_REQUEST['mode']) == 'expired') Errors are now resolved. Guess I was having a brain fart and was putting the closing ) in the wrong place. Sorry for the question.
  8. Hello, forgive me for this question in advance. I have looked all day for a fix to this and nothing I have come across has resolved this. My host upgraded to the most recent PHP several months ago and since it has thrown errors on certain scripts. I have gotten tired of looking at them and haven't been able to find a fix on my own so here I am. I am getting the below error. Notice: Undefined index: mode in /home4/mesquiu0/public_html/NSDisplay/NSStorms-include.php on line 38 if ($_REQUEST['mode'] == 'expired') { // We only want the expired storms $filetoRead = $expiredfile; $arraytoUse = $Expired; } else { $filetoRead = $stormfile; $arraytoUse = $Active; } I am pretty sure it needs an inset call but not sure how to go about formatting that as I have done with the others errors I have come across. Any suggestions to this error? -Thanks!
  9. Thanks, I knew where I need to make the change I just wasn't aware of I need to format the change since I needed it in mins instead of hour so 15 * 3600 wouldn't work because it would be 15 hrs. I am not real familiar with using magic numbers so wasn't sure. I did apply your suggestion as I do like that method better. -Thanks
  10. I believe i have found my answer. Would this be correct? 15 * 60
  11. Hello, I have a small script that uses filemtime. It checks the last updated time and if it within X amount of time it will show ONLINE otherwise it will show OFFLINE. Currently it is set for two hours since I built this off the php examples which used two hours. How can I adjust this so that if it is 15 mins old it shows OFFLINE instead of 2 hours? Here is the code I am using for example. -Thanks <?php //Styling of text $offline = "color:#FF0000; font-weight: bold; font-size:14px;"; $online = "color:#228B22; font-weight: bold; font-size:14px;"; //Check age of image and if older then 15 mins display offline otherwise online $filename = './gr3/animatedcr.gif'; if (time()-filemtime($filename) > 2 * 3600) { echo "<div style='$offline'> OFFLINE</div>"; } else { echo "<div style='$online'> ONLINE</div>"; } ?>
  12. Thanks but, this is not my feed so I have no control over how it is styled. It comes as is so I can't alter it With that said. Could I use something to remove it? Not sure what I could use that would just remove the div.
  13. Hello, I have this XML file I am parsing and I have hit a small formatting issue that I can't seem to get around. Here is what the the output of the RSS looks like. <description><![CDATA[<div style='text-align:left;'>Exit ramp closed. <br/><b>Current Status:</b> Open<br/><b>Affected Lanes:</b> Exit Ramp<br/><b>Dates:</b> Wednesday, May 28 - Thursday, May 29<br/><b>Days Closed:</b> <font color='#808080'>S</font><font color='#808080'>M</font><font color='#808080'>T</font><font color='#FF0000'><b>W</b></font><font color='#FF0000'><b>T</b></font><font color='#808080'>F</font><font color='#808080'>S</font> 20:00 PM - 6:00 AM</div>]]></description> Notice at the first is "Exit ramp closed." There is nothing before it but, for some weird reason when I parse it. It is on a new line like so, notice it should be up there with "Incident" but, it is dropped down below it. Incident: Exit ramp closed. Current Status: Open Affected Lanes: Exit Ramp Dates: Wednesday, May 28 - Thursday, May 29 Days Closed: SMTWTFS 20:00 PM - 6:00 AM This is how it is formated in the td cell. <td style='{$td2Style}'><strong>Incident:</strong> {$incident_data_desc}</td>\n"; So as you can see above, there is nothing before it that would cause it to break to a new line both in the table or in the RSS. So how can I remove that first return only is that is on the same line with it and not below it. I have tried this and a couple of other things like trim with no luck. $description = $item->description; $incident_data_desc = str_replace("\r", '', $description ); Note, I only need that first one removed, the others are fine. I can do it but it will remove all the breaks and I only want to remove that first one that is causing the line to be on a new line. Any suggestions? -Thanks
  14. I got it sorted. I had another brain fart moment. I need to change this. channel->pubDate; to this
  15. Yes, that is correct. I want each entry its own table. This would probably be less painless if each entry included its own pubDate in stead of just for the overall feed.
  16. Thanks that is what I thought. The issue I was fighting with that is when the data is outside the loop it doesn't pull the data. Not sure why as they doesn't need to be in it as you're right. Is this right? //Lets load the XML file for the loop $xml = simplexml_load_file($lane_data); $incident_data_date = $channel->pubDate; $incident_data_updated = DATE("D, M d, g:i A", STRTOTIME($incident_data_date)); //Set initial output to false $tData = false; foreach($xml->channel->item as $item) { $incident_data_title = $item->title; $incident_data_desc = $item->description; // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'>Updated: {$incident_data_updated}</td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'><strong>Roadway:</strong> {$incident_data_title}</td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'><strong>Description:</strong> {$incident_data_desc}</td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; } echo $tData;
  17. Revisiting this since I am able to test it with a live feed now. The feed only shows one entry but yet it is being duplicated twice and I am unsure what is causing this. The other day it would repeat 3 or 4 times. I am not sure what is causing this. Any suggestions? http://www.mesquiteweather.net/inc-weather_radio_alert.php //Set initial output to false $tData = false; $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); foreach ($result as $entry): $event[] = $entry->children("cap", true)->event; endforeach; endif; $alertValue = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Flood Advisory', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement'); $events = array_intersect($alertValue, $event); $message = array_shift($events); // Set the alert colors for the banner background include ('inc-NWR-alert-colors.php'); // Lets assign some styles for the banner $bannerStyle = '"color: #FFF; width:100%; border-top-style:solid; border-bottom-style:solid; border-color:#FFF; border-width:1px; font-size:11px; font-weight:normal; font-family: Arial,Helvetica,sans-serif; text-align: center; background-color:' .$alertColor. '; margin-bottom:5px; padding: .2em 0em .2em 0em"'; // Lets assembly the banner to display $radiowarning = '<div style='.$bannerStyle.'> <strong>SEVERE WEATHER ALERT - '.$message.'</strong>... Listen now to our LIVE NOAA Weather Radio Stream <a href="'.$feed.'" onclick="return popup(this, \'noaa\')" title="Live NOAA Radio For Dallas County"><span style="color:FFF">[Click here to listen]</span></a> </div>'; foreach( $alertValue as $alert ) { if (in_array($alert, $event)) { echo $radiowarning; } }
  18. Thanks Barand, I realized that and got it sorted before I saw this. I was coming back to update it. Now the problem is, it's not looping through each entry, it only displays the first one. //Lane closure data $lane_data = "http://dfwtraffic.dot.state.tx.us/DalTrans/GetFile.aspx?FileName=MapBurnerOutput/LaneClosures.rss&Exact=true"; //Lets load the XML file for the loop $xml = simplexml_load_file($lane_data); //Set initial output to false $tData = false; foreach($xml->channel as $channel) { $incident_data_title = $channel->item->title; $incident_data_desc = $channel->item->description; $incident_data_date = $channel->pubDate; $incident_data_updated = DATE("D, M d, g:i a", STRTOTIME($incident_data_date)); // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'>Updated: {$incident_data_updated}</td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'><strong>Roadway:</strong> {$incident_data_title}</td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'><strong>Description:</strong> {$incident_data_desc}</td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; } echo $tData;
  19. Hello all, I have a very simple issue that I am having problems with. I have done this several times but not sure what I am missing. Probably just a brain fart and need a second set of eyes. I have a XML URL I am parsing with SimpleXML and for some reason it isn't pulling the data now that I have included it in a loop. Just trying to pull each entry and put it in its own table. This is something I have done over and over but I am missing something. Only listing the relevant code. The echo statement is further down the page and not included in the snippet. //Set path to data files //Incidents XML URL $incident_data = "http://dfwtraffic.dot.state.tx.us/DalTrans/GetFile.aspx?FileName=MapBurnerOutput/Incidents.rss&Exact=true"; //Lets load the XML file for the loop $xml = simplexml_load_file($incident_data); //Set initial output to false $tData = false; foreach($xml->channel as $channel) { $incident_data_title = $channel->item['title']; $incident_data_desc = $channel->item['description']; $incident_data_date = $channel['pubDate']; $incident_data_updated = DATE("D, M d, g:i a", STRTOTIME($incident_data_date)); // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'>Updated: {$incident_data_updated}</td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'><strong>Incident:</strong>{$incident_data_title}</td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'><strong>Description:</strong>{$incident_data_desc}</td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; } Here is a sample of the XML file I am parsing. Very simple and not complicated. I can parse data outside the loop but, once I add it inside the loop it doesn't pull anything. <?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:c2c="http://its.gov/c2c_icd" xmlns:tti="urn:tti"> <channel> <title>Dallas Area Freeway Incidents </title> <link>http://dfwtraffic.dot.state.tx.us</link> <language>en-us</language> <category domain="dfwtraffic.dot.state.tx.us">LaneClosures</category> <lastBuildDate>5/11/2014 8:35:35 PM</lastBuildDate> <pubDate>5/11/2014 8:35:35 PM</pubDate> <image> <url>http://dfwtraffic.dot.state.tx.us/images/daltranslogo.gif</url> <link>http://dfwtraffic.dot.state.tx.us</link> </image> <item> <guid isPermaLink="false">200b64713c084791a12e34245791a575</guid> <title>VehicleCollision - Westbound IH 30 @ Westmoreland Rd</title> <link>http://dfwtraffic.dot.state.tx.us</link> <description><![CDATA[<div text-align:left;'><b>Status:</b> Verified at 8:31 PM on Sunday, May 11<br/><b>Affected Lanes:</b> Lane 1, Lane 2, Lane 3</div>]]></description> </item> </channel> </rss> What am I missing? -Thanks
  20. That's what I did if you notice from the code above. The issue I am seeing is since we are now pulling every value from $event. If the event is issued more than once then it will display more than once. Not a big deal if I am using only the county feed as it can only have one of the same event issued at a time but, on a state level there could be multiple events of the same priority.
  21. Ok I think I got this sorted out and working now. Does this look right? //Set initial output to false $tData = false; $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); foreach ($result as $entry): $event[] = $entry->children("cap", true)->event; endforeach; endif; $alertValue = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Flood Advisory', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement'); $events = array_intersect($alertValue, $event); $message = array_shift($events); // Set the alert colors for the banner background include ('inc-NWR-alert-colors.php'); // Lets assign some styles for the banner $bannerStyle = '"color: #FFF; width:100%; border-top-style:solid; border-bottom-style:solid; border-color:#FFF; border-width:1px; font-size:11px; font-weight:normal; font-family: Arial,Helvetica,sans-serif; text-align: center; background-color:' .$alertColor. '; margin-bottom:5px; padding: .2em 0em .2em 0em"'; // Lets assembly the banner to display $radiowarning = ' <div style='.$bannerStyle.'> <strong>SEVERE WEATHER ALERT - '.$message.'</strong>... Listen now to our LIVE NOAA Weather Radio Stream <a href="'.$feed.'" onclick="return popup(this, "noaa")" title="Live NOAA Radio For Dallas County">[Click here to listen]</a> </div>'; foreach( $alertValue as $alert ) { if (in_array($alert, $event)) { echo $radiowarning; } } The only small issue I am running into is since there 3 instances of the same alert current at the time it is showing it 3 times. How would I go about only showing it once? This won't be a problem when I am using it on the county feed but state feed it could cause problems as I am seeing. http://www.mesquiteweather.net/wxtest.php
  22. Ok, I think I have found my issue with the below code that parses the XML file. //Set initial output to false $tData = false; $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); foreach ($result as $entry): $event = $entry->children("cap", true)->event; endforeach; endif; Now the variable $event is what pulls the alert titles. Through more trouble shooting I have found out that $event is only returning one value when it should be returning more and it is only pulling the last value in the list. So it only has one value to compare against. I guess I need to figure out how to pull all the values for the variable to put into an array. When I put this inside the loop I am able to pull all the values for the variable but then I am stuck again. $titles = array($event); $alertValue = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement'); $events = array_intersect($alertValue, $titles); $message = array_shift($events); echo $message; Any suggestions?
  23. There has got to be an easier way to get set the priority and it if a value with a high priority matches a value for the XML variable then display it. Unless I am doing something wrong which is highly likely then it doesn't work but it seems there is an easier way. $titles = array($event); $alertValue = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement'); $events = array_intersect($alertValue, $titles); $message = array_shift($events); print_r($message); It still outputs the same low priority value. It should be showing Severe Thunderstorm Warning because that is a higher priority which is set as in $alertValue. http://www.mesquiteweather.net/wxtest.php Here is a list of active events which there are some that have higher priority. http://alerts.weather.gov/cap/tx.php?x=1 I don't need it to show all up them, just one and just the highest one by the priority which I set.
  24. How did you arrive at that. Where did $events and $intersect come from? If I understand this correctly it will print then entire array within the prioritized order. That is like sort but, it dosen't explain how to print only the highest priority event. I can do all this with sort but it's going to display the entire list in a certain order if those events exist and not just the single highest one.
  25. Now that I have one problem sorted I have a new one. This is kind of like a sort but with a sort it will display then entire array in a certain order. I don't want to display the entire array just a certain value by it's set priority. I have a variable which is created from parsing an XML file. This variable has 120+ possible values since it is XML and constantly changing. I only want to display 9 of those possible values which I have those singled out now. I only want to show one of them and to determine which one I show I want to put them in a certain order by priority and display the highest priority one from the array. I don't know how to go about this since sort will display then entire array just in the order you place it. I really can't find any examples of what I am needing to do. This is the order I am needing them to display in if they exist and how it breaks down. $event pulls the possible titles from the XML file like so. This works great, no problems here at all. //Set initial output to false $tData = false; $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); foreach ($result as $entry): $event = $entry->children("cap", true)->event; endforeach; endif; Now the only problem I should say with the above is if the $event variable contains more than one of the values I want to display in the list it will display the first one from the XML. So I need to be able to prioritize the values below and sort through that and only show the highest priority value should more than one exist I hope this makes sense. $alertvalue = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Tornado Watch', 'Severe Thunderstorm Watch', 'Flash Flood Warning', 'Flash Flood Watch', 'Flood Warning', 'Flood Watch', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory', 'Special Weather Statement'); If this was a normal sort it would be easy but I don't want to print the entire array just the highest priority one from the array.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.