Jump to content

Texan78

Members
  • Posts

    272
  • Joined

  • Last visited

Everything posted by Texan78

  1. No, the variable is already assigned and outputting from XML. That works fine. I just need to assign colors to the values from the $severity variable that is produced from the XML. That way when it is outputted in my HTML each value has an assigned color.
  2. No problem, I have some sample code in my original post. That is from a working script I has that takes the values from a variable and assigns dynamic colors to the text. The values from the XML file with the variable $severity could be 4 possible outcomes Extreme, Severe, Moderate, Minor. So basically it will take the values from the XML file with the variable $severity and if it's Extreme it will assign it as Extreme then Moderate etc and that is how it will show outputted to the page. Here is an example of what it will look like http://www.mesquiteweather.net/wxsvr.php That is actually the page it will be used on. Right now the color is being assigned inline but I need it to be assigned dynamically based on the vaule in an array but I am not sure how to put that together. I have just started using PHP with XML so it's a little different then a normal array but I know it can be done as I have a script that does that same thing for something else. I am just not sure how it is constructed. The code from my first post is the code used and the general idea.
  3. Thank you for your reply. I know it's a little hard to understand. I agree with you on the CSS part and on my site I will do that as I prefer it that way as well. Unfortunately since this script will be shared with others. Having the inline styles makes the setup a little more easier and straight forward for others to setup on their sites. What I am needing is to take the values of $severity which are generated from the XML file I parsed which is a total of four values. Loop them through an array and assign each value a color. Then produce a new variable based on that array that I could using as the global variable for the output. In your example I don't see how the color is assigned based on value. I hope that's a little better explanation. If you need some more information just let me know. -Thanks
  4. Forgive me if the topic isn't correct. I will try to explain this the best I can as I am not sure how to explain this in the proper terms. I have an XML file which I have parsed. The variable I have created from the XML element to output is $severity. It works great and outputs a value in my table. The value could be 4 different things. Extreme, Severe, Moderate, Minor. I want to be able to assign a certain color to each one of the 4 values for when it's displayed. I have another script which I didn't write which does this. Here is an example of what it looks like. Keep in mind $severity is the variable from the XML file. I added that for example purposes but that is the variable that will return these values below. if(!empty($severity) and $severity == 'Extreme') { $intensity = '<span style="color: red"><b> '.$intensity.' </b></span>';} // change intensity color if(!empty($severity) and $severity == 'Severe') { $intensity = '<span style="color: #F66"><b> '.$intensity.' </b></span>';} // change intensity color if(!empty($severity) and $severity == 'Moderate') { $intensity = '<span style="color: #FF9"><b> '.$intensity.' </b> </span>';} // change intensity color if(!empty($severity) and $severity == 'Minor') { $severity = '<span style="color: #FF6600"><b> '.$intensity.' </b> </span>';} // change intensity color I am sure this is incomplete but you get the idea. I am sure I need to create an array but I am not sure how to properly write this so it assigns a set color to each value I include it in my HTML for output. If I need to provide any additional information please let me know. Once again I apologize for the vague description. I hope this makes sense. -Thanks
  5. Oh my you're a saint!!! Thank you so much that works like a charm! I knew it was something simple and out of all the searching I did nothing made it that simple. Yes, I agree strongly to allow variable-variable notation with namespaces. That would simplify things tremendously! -Thanks again!
  6. Hello, I have a small problem and I have been searching for hours. While I have found many results. I really haven't found one that works with the code I am currently using or I am just not knowledgeable enough about it. I am using SimpleXML to parse a XML feed. I have never used SimpleXML so I decided on this current script I would give it a shot. This is the structure of the XML I am working with below. The elements with the namespaces I am needing is <cap:event>, <cap:effective>, <cap:expires>, <cap:severity> <entry> <id>http://alerts.weather.gov/cap/wwacapget.php?x=TX124EFFB832F0.SpecialWeatherStatement.124EFFB84164TX.LUBSPSLUB.ac20a1425c958f66dc159baea2f9e672</id> <updated>2013-05-06T20:08:00-05:00</updated> <published>2013-05-06T20:08:00-05:00</published> <author> <name>w-nws.webmaster@noaa.gov</name> </author> <title>Special Weather Statement issued May 06 at 8:08PM CDT by NWS</title> <link href="http://alerts.weather.gov/cap/wwacapget.php?x=TX124EFFB832F0.SpecialWeatherStatement.124EFFB84164TX.LUBSPSLUB.ac20a1425c958f66dc159baea2f9e672"/> <summary>...SIGNIFICANT WEATHER ADVISORY FOR COCHRAN AND BAILEY COUNTIES... AT 808 PM CDT...NATIONAL WEATHER SERVICE DOPPLER RADAR INDICATED A STRONG THUNDERSTORM 30 MILES NORTHWEST OF MORTON...MOVING SOUTHEAST AT 25 MPH. NICKEL SIZE HAIL...WINDS SPEEDS UP TO 40 MPH...CONTINUOUS CLOUD TO GROUND LIGHTNING...AND BRIEF MODERATE DOWNPOURS ARE POSSIBLE WITH</summary> <cap:event>Special Weather Statement</cap:event> <cap:effective>2013-05-06T20:08:00-05:00</cap:effective> <cap:expires>2013-05-06T20:45:00-05:00</cap:expires> <cap:status>Actual</cap:status> <cap:msgType>Alert</cap:msgType> <cap:category>Met</cap:category> <cap:urgency>Expected</cap:urgency> <cap:severity>Minor</cap:severity> <cap:certainty>Observed</cap:certainty> <cap:areaDesc>Bailey; Cochran</cap:areaDesc> <cap:polygon>34.19,-103.04 34.19,-103.03 33.98,-102.61 33.71,-102.61 33.63,-102.75 33.64,-103.05 34.19,-103.04</cap:polygon> <cap:geocode> <valueName>FIPS6</valueName> <value>048017 048079</value> <valueName>UGC</valueName> <value>TXZ027 TXZ033</value> </cap:geocode> <cap:parameter> <valueName>VTEC</valueName> <value></value> </cap:parameter> </entry> This is a sample of the php I am using to parse the XML and it works great for normal non-namespace elements. It does exactly what I need it to do. My question is, what do I need to do to parse the elements with namespaces cap: with the including code below? ini_set('display_errors','1'); $tdata = ""; $data = "http://alerts.weather.gov/cap/tx.php?x=1"; $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): $title = $entry->title; $summary = $entry->summary; $tdata .= "<p><strong>$title</strong></p><p>$summary</p><hr/>"; endforeach; endif; Any suggestions would be greatly appreciated as I have gotten this far and I can't seem to tackle this last small obstacle. -Thanks
×
×
  • 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.