Jump to content

Texan78

Members
  • Posts

    272
  • Joined

  • Last visited

Everything posted by Texan78

  1. This shouldn't have been hidden before since e_reporting was on. They didn't become errors until the update. $noStormMessage is defined that is the thing. If that is the problem then $tData would also be showing as undefined. changing .= to =. does nothing. $stormTypesAry is clearly defined before it is used if you look closely. I am not sure what you're trying to say.
  2. It appears my host has done some upgrades to the latest PHP. Since this update some of my scripts are throwing errors. I am not sure why these errors are being generated as it looks ok to me. I can turn error reporting off and they go away but I would rather do it right and fix the error. The errors don't cause the script to not work, just throws the annoying error. Maybe I just need another set of eyes and someone with a little more experience than I have as the variable looks to be defined unless I am missing something. Here is the page http://www.mesquiteweather.net/wxspotter.php Here is where it says the error starts $noStormMessage .= "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n"; $noStormMessage .= "<tbody>\n"; $noStormMessage .= " <tr><td style='{$td1Style}'>LIVE STORM SPOTTER REPORTS</td></tr>\n"; $noStormMessage .= " <tr><td style='{$td4Style}'>There are currently no storm reports</td></tr>\n"; $noStormMessage .= "</tbody>\n"; $noStormMessage .= "</table>\n"; $noStormMessage .= $afterTable; Here is the full script <?php ####################################################################################### # # SPOTTER NETWORK STORM REPORTS # version 1.00 # # This program is free and no license is required. # # # mesquiteweather.net # ####################################################################################### //// SETTINGS //// //// SETTINGS //// $bkgColor = '#d4d4d4'; // Background color Examples: "gray" "#CCC" "#CCCCCC" $bc = '#EEEEEE'; // Background color of table cells $dtColor = '#FFF'; // Date & time color Examples: "#FC0" "#FFCC00" "white" $width = '100%'; // Set the width of the report tables //// END OF SETTINGS //// ####################################################################################### ini_set('display_errors','1'); ## Start Configurable data ## //Set path to data file $data = "http://www.spotternetwork.org/data.php"; ## End Configurable data ## // overrides from the Carter Lake Settings.php file (if applicable) global $SITE; if(isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir']; } if (isset($SITE['imagesDir'])) {$imagesDir = $SITE['imagesDir'];} if(isset ($SITE['tz'])) {$ourTZ = $SITE['tz'];} if(!function_exists('date_default_timezone_set')) { putenv("TZ=" . $ourTZ); } else { date_default_timezone_set("$ourTZ"); } // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; // set borders $bbrdr = 'border-bottom:thin solid black'; // bottom $lbrdr = 'border-left:thin solid black'; // left $rbrdr = 'border-right:thin solid black'; // right $tbrdr = 'border-top:thin solid black'; // top $sbrdr = 'border-right:thin solid black; '. 'border-left:thin solid black'; // side //Define table to display after each storm report $afterTable = "<table style='margin-bottom: 5px;' border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td></tr><tbody></table>\n"; // Let's assign the table some styles $noMessageStyle = "width:{$width}; text-align:center; 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;"; $td3Style = "{$sbrdr}; line-height:5px;"; $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px;"; //Set message to display if there were not report $noStormMessage .= "<table style='{$noMessageStyle}' cellpadding='0' cellspacing='0'>\n"; $noStormMessage .= "<tbody>\n"; $noStormMessage .= " <tr><td style='{$td1Style}'>LIVE STORM SPOTTER REPORTS</td></tr>\n"; $noStormMessage .= " <tr><td style='{$td4Style}'>There are currently no storm reports</td></tr>\n"; $noStormMessage .= "</tbody>\n"; $noStormMessage .= "</table>\n"; $noStormMessage .= $afterTable; $xml = simplexml_load_file($data); //Set initial output to false $tData = false; foreach($xml->report as $report) { $date = $report['stamp']; $time = strtotime($date.'UTC'); $dateInLocal = date("D g:i a", $time); $narrative = $report['narrative']; $loc = $report['city1']; $tz = $report['tz']; $stormType = 'Unknown'; foreach($report->attributes() as $typeKey => $id) { if($id == 1) { if(array_key_exists($typeKey, $stormTypesAry)) { $stormType = $stormTypesAry[$typeKey]; } break; } } $stormTypesAry = array( 'tornado' => 'Tornado', 'funnelcloud' => 'Funnel Cloud', 'wallcloud' => 'Wall Cloud', 'rotation' => 'Rotation', 'hail' => 'Hail', 'wind' => 'Wind', 'flood' => 'Flood', 'flashflood' => 'Flash Flood' ); $stormTypesAry['tornado'] = array('name' => 'Tornado', 'color' => 'rgba(255, 0, 0, 0.2)'); $stormTypesAry['funnelcloud'] = array('name' => 'Funnel Cloud', 'color' => 'rgba(255, 100, 0, 0.2)'); $stormTypesAry['wallcloud'] = array('name' => 'Wall Cloud', 'color' => 'rgba(255, 255, 0, 0.2)'); $stormTypesAry['rotation'] = array('name' => 'Rotation', 'color' => 'rgba(255, 228, 181, 0.2)'); $stormTypesAry['hail'] = array('name' => 'Hail', 'color' => 'rgba(160, 0, 255, 0.2)'); $stormTypesAry['wind'] = array('name' => 'Wind', 'color' => 'rgba(235, 235, 250, 1.0)'); $stormTypesAry['flood'] = array('name' => 'Flood', 'color' => 'rgba(0, 255, 0, 0.2)'); $stormTypesAry['flashflood'] = array('name' => 'Flash Flood', 'color' => 'rgba(0, 255, 50, 0.2)'); $stormTypesAry['Other'] = array('name' => 'Other', 'color' => 'rgba(0, 255, 50, 0.2)'); $reportColor = ''; // get the stormType and reportColor using the $typeKey $stormType = $stormTypesAry[$typeKey]['name']; $reportColor = $stormTypesAry[$typeKey]['color']; // this line takes the place of all the switch/case logic // Set table style $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:{$reportColor};"; $td3Style = "{$sbrdr}; line-height:5px; background-color:{$reportColor};"; $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$reportColor};"; // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'><b>{$stormType}</b></td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'>Reported: <b>{$dateInLocal}</b> - </b>Location: <b>{$loc}</b></td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'>Description: <b>{$narrative}</b></td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; $tData .= $afterTable; } //If no storms were in the source, set no storm message if(!$tData) { $tData = $noStormMessage; } echo $tData; ?>
  3. Could someone offer some insight on what this error means exactly. My server did some upgrades over the weekend and went to PHP 5.4 and now I am getting this error on some of my scripts. I did a search but can't trace down exactly what it means in my case. -Thanks!
  4. Well I can't edit the the above post but I got it sorted. I was missing a period before the = sign on the nostormmessage. $noStormMessage .= All working great now.
  5. Thank you, that currently similar to how I have it now but it doesn't work correctly. This is what I have done and what I have done in the past but it still isn't working correctly. For my no storm message I have this. if (preg_match("/No thunderstorms detected/i", $trac)) { $noStormMessage = "<table style='{$tracTable}'> <tr> <td style='{$td1Style}'>No nearby thunderstorms detected</td> </tr> </table>"; } else { Then from there is there is a storm and data it goes to this. // If there are thunderstorms, process them, putting them into various arrays // $tnumber[x] is for number of thunderstorms preg_match("/Tracking (.*) thunderstorms/Uis", $tracnopara, $tnumber); // $tid[x] is the ID number of the storm preg_match_all("/Thunderstorm ID (.*) detected/Uis", $tracnopara, $temp); $tid = $temp[1]; // $tdtime[x] is the time detected preg_match_all("/detected (.*)=/Uis", $tracnopara, $temp); $tdtime = $temp[1]; // $tdirection[x] is the direction of the storm preg_match_all("/Storm location bearing (.*) dgr/Uis", $tracnopara, $temp); $tdirection = $temp[1]; // $tdistance[x] is the distance in $measure amounts preg_match_all("/distance (.*) $measure/Uis", $tracnopara, $temp); $tdistance = $temp[1]; //$tintensity[x] is the intensity of the storm preg_match_all("/Intensity class (.*)=/Uis", $tracnopara, $temp); $tintensity = $temp[1]; //$ttrend[x] is the trend of the storm preg_match_all("/Intensity trend (.*)=/Uis", $tracnopara, $temp); $ttrend = $temp[1]; //$tcurraterate[x] Current strikerate preg_match_all("/current strikerate (.*)=/Uis", $tracnopara, $temp); $tcurraterate = $temp[1]; //$tpeakrate[x] Peak strikerate preg_match_all("/peak strikerate (.*)=/Uis", $tracnopara, $temp); $tpeakrate = $temp[1]; //$tpeakrate[x] Total recorded strikes preg_match_all("/total recorded strikes (.*)=/Uis", $tracnopara, $temp); $ttotalstrikes = $temp[1]; //$tactivity[x] Last recorded activity preg_match_all("/recorded activity (.*)=/Uis", $tracnopara, $temp); $tactivity = $temp[1]; // Set working for the header based on number of thunderstorms if ($tnumber[1] == 1){ } // This builds each line of text for each thunderstorm // begin your table $tracreport .= "<div id='tracReport'><table style='{$tracTable}'> <tr> <td style='{$td1Style}'> Tracking " . $tnumber[1] . " active thunderstorms</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='{$tr1Style}'>Cell ID</td> <td style='{$tr1Style}'>Tracking Since</td> <td style='{$tr1Style}'>Bearing</td> <td style='{$tr1Style}'>Distance</td> <td style='{$tr1Style}'>Intensity</td> <td style='{$tr1Style}'>Trend</td> <td style='{$tr1Style}'>Current Rate</td> <td style='{$tr1Style}'>Peak Rate</td> <td style='{$tr1Style}'>Total</td> <td style='{$tr1Style}'>Last Strike</td> </tr>"; // break the top part of the table // create your loop foreach($tid as $k => $v){ // pass in storm intensity for current storm switch(strtolower(trim($tintensity[$k]))) { case 'weak': $stormIntensity = 'rgb(0, 255, 0)'; break; case 'moderate': $stormIntensity = 'rgb(255, 255, 0)'; break; case 'strong': $stormIntensity = 'rgb(255, 102, 0)'; break; case 'severe': $stormIntensity = 'rgb(198, 1, 204)'; break; } // replace default color with $stormIntensity $intCat = str_replace('color: #FFF;', "color: $stormIntensity;", $tr2Style); // pass in storm intensity for current storm switch(strtolower(trim($ttrend[$k]))) { case 'weakening': $stormTrend = 'rgb(0, 255, 0)'; break; case 'steady': $stormTrend = 'rgb(255, 255, 0)'; break; case 'intensifying': $stormTrend = 'rgb(255, 0, 0)'; break; } // replace default color with $stormIntensity $treCat = str_replace('color: #FFF;', "color: $stormTrend;", $tr2Style); $tracreport .= "<tr> <td style='{$intCat}'>" . $tid[$k] . "</td> <td style='{$tr2Style}'>" . $tdtime[$k] . "</td> <td style='{$tr2Style}'>" . $tdirection[$k] . "°</td> <td style='{$tr2Style}'>" . $tdistance[$k] . " miles</td> <td style='{$intCat}'>" . $tintensity[$k] . "</td> <td style='{$treCat}'>" . $ttrend[$k] . "</td> <td style='{$tr2Style}'>" . $tcurraterate[$k] . "</td> <td style='{$tr2Style}'>" . $tpeakrate[$k] . "</td> <td style='{$tr2Style}'>" . $ttotalstrikes[$k] . "</td> <td style='{$tr2Style}'>" . $tactivity[$k] . "</td> </tr>"; } // close your loop // finish your table $tracreport .= "</table> </td> </tr> </table></div>"; } Then I put it all together like this. //If no storms were in the source, set no storm message if(!$tracreport) { $tracreport = $noStormMessage; } echo $tracreport; But when there is no data it shows an empty table and not the no storm message table from the beginning of the code. I am sure it is something easy I am missing but not sure what. -Thanks
  6. Hello, I have this able below that is populated via data dynamically via a text file. It works great. What I am wanting to do and I had it like this at one point and did something and now it does work like it use to. I want to hide the header row when there is now data. Please see screen shots for examples. Here is what it looks like with data. Works perfect as it should. Ok here is what it looks like without data. Notice the top row is still showing. I want to hide this row if there is no data but, I can't put it in the loop or it will repeat that row each time, at least that's what I think will happen as I tried it once. Maybe I was doing something wrong. So I want that top row to be hidden if there is no data and only show this when there is no data. Like I said, it use to do this at one point but not sure what I changed to cause this to not work like that anymore. So how can I hide that row when there is no data without adding it in the loop and causing it to repeat for each line of data? Here is the code for the table and loop.... // This builds each line of text for each thunderstorm // begin your table $tracreport .= "<div id='tracReport'><table style='{$tracTable}'> <tr> <td style='{$td1Style}'> Tracking " . $tnumber[1] . " active thunderstorms</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='{$tr1Style}'>Cell ID</td> <td style='{$tr1Style}'>Tracking Since</td> <td style='{$tr1Style}'>Bearing</td> <td style='{$tr1Style}'>Distance</td> <td style='{$tr1Style}'>Intensity</td> <td style='{$tr1Style}'>Trend</td> <td style='{$tr1Style}'>Current Rate</td> <td style='{$tr1Style}'>Peak Rate</td> <td style='{$tr1Style}'>Total</td> <td style='{$tr1Style}'>Last Strike</td> </tr>"; // break the top part of the table // create your loop foreach($tid as $k => $v){ // pass in storm intensity for current storm switch(strtolower(trim($tintensity[$k]))) { case 'weak': $stormIntensity = 'rgb(0, 255, 0)'; break; case 'moderate': $stormIntensity = 'rgb(255, 255, 0)'; break; case 'strong': $stormIntensity = 'rgb(255, 102, 0)'; break; case 'severe': $stormIntensity = 'rgb(198, 1, 204)'; break; } // replace default color with $stormIntensity $intCat = str_replace('color: #FFF;', "color: $stormIntensity;", $tr2Style); // pass in storm intensity for current storm switch(strtolower(trim($ttrend[$k]))) { case 'weakening': $stormTrend = 'rgb(0, 255, 0)'; break; case 'steady': $stormTrend = 'rgb(255, 255, 0)'; break; case 'intensifying': $stormTrend = 'rgb(255, 0, 0)'; break; } // replace default color with $stormIntensity $treCat = str_replace('color: #FFF;', "color: $stormTrend;", $tr2Style); $tracreport .= "<tr> <td style='{$intCat}'>" . $tid[$k] . "</td> <td style='{$tr2Style}'>" . $tdtime[$k] . "</td> <td style='{$tr2Style}'>" . $tdirection[$k] . "°</td> <td style='{$tr2Style}'>" . $tdistance[$k] . " miles</td> <td style='{$intCat}'>" . $tintensity[$k] . "</td> <td style='{$treCat}'>" . $ttrend[$k] . "</td> <td style='{$tr2Style}'>" . $tcurraterate[$k] . "</td> <td style='{$tr2Style}'>" . $tpeakrate[$k] . "</td> <td style='{$tr2Style}'>" . $ttotalstrikes[$k] . "</td> <td style='{$tr2Style}'>" . $tactivity[$k] . "</td> </tr>"; } // close your loop // finish your table $tracreport .= "</table> </td> </tr> </table></div>"; } echo $tracreport; And here is the entire code in case it helps any. <?php // The TRACreportshort takes Nexstorm's full TRACreport and shortens it to a more // managable size for displaying. // // It chops up the vital storm cell info, places it in arrays, and redisplays it as we wish // // Set some default values $measure = "mi"; // km, nm, or mi depending on your Nexstorm measurements // Let's assign the tables some styles $tracTable = "width:100%; margin-top: 15px; background-color:#000; color:#FFF;"; $td1Style = "padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;"; $tr1Style = "background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;"; $tr2Style = "background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;"; // Load the TRACreport and remove carriage returns, change the word 'no change' to 'steady' $trac = implode('', file('lightning/nexstorm/TRACReport.txt')); $tracnopara = preg_replace( '|\n|', '=', $trac ); $tracnopara = preg_replace( '|No change|', 'Steady', $tracnopara ); $tracnopara = preg_replace( '|/minute|', ' a min', $tracnopara); // If there aren't any thunderstorms, then say it if (preg_match("/No thunderstorms detected/i", $trac)) { $tracreport = "<table style='{$tracTable}'> <tr> <td style='{$td1Style}'>No nearby thunderstorms detected</td> </tr> </table>"; } else { // If there are thunderstorms, process them, putting them into various arrays // $tnumber[x] is for number of thunderstorms preg_match("/Tracking (.*) thunderstorms/Uis", $tracnopara, $tnumber); // $tid[x] is the ID number of the storm preg_match_all("/Thunderstorm ID (.*) detected/Uis", $tracnopara, $temp); $tid = $temp[1]; // $tdtime[x] is the time detected preg_match_all("/detected (.*)=/Uis", $tracnopara, $temp); $tdtime = $temp[1]; // $tdirection[x] is the direction of the storm preg_match_all("/Storm location bearing (.*) dgr/Uis", $tracnopara, $temp); $tdirection = $temp[1]; // $tdistance[x] is the distance in $measure amounts preg_match_all("/distance (.*) $measure/Uis", $tracnopara, $temp); $tdistance = $temp[1]; //$tintensity[x] is the intensity of the storm preg_match_all("/Intensity class (.*)=/Uis", $tracnopara, $temp); $tintensity = $temp[1]; //$ttrend[x] is the trend of the storm preg_match_all("/Intensity trend (.*)=/Uis", $tracnopara, $temp); $ttrend = $temp[1]; //$tcurraterate[x] Current strikerate preg_match_all("/current strikerate (.*)=/Uis", $tracnopara, $temp); $tcurraterate = $temp[1]; //$tpeakrate[x] Peak strikerate preg_match_all("/peak strikerate (.*)=/Uis", $tracnopara, $temp); $tpeakrate = $temp[1]; //$tpeakrate[x] Total recorded strikes preg_match_all("/total recorded strikes (.*)=/Uis", $tracnopara, $temp); $ttotalstrikes = $temp[1]; //$tactivity[x] Last recorded activity preg_match_all("/recorded activity (.*)=/Uis", $tracnopara, $temp); $tactivity = $temp[1]; // Set working for the header based on number of thunderstorms if ($tnumber[1] == 1){ } else { // Sometimes the TRACreport is empty so we need to say that //$tracreport = "<br />No data currently available or thunderstorms detected.<br/>"; } // This builds each line of text for each thunderstorm // begin your table $tracreport .= "<div id='tracReport'><table style='{$tracTable}'> <tr> <td style='{$td1Style}'> Tracking " . $tnumber[1] . " active thunderstorms</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='{$tr1Style}'>Cell ID</td> <td style='{$tr1Style}'>Tracking Since</td> <td style='{$tr1Style}'>Bearing</td> <td style='{$tr1Style}'>Distance</td> <td style='{$tr1Style}'>Intensity</td> <td style='{$tr1Style}'>Trend</td> <td style='{$tr1Style}'>Current Rate</td> <td style='{$tr1Style}'>Peak Rate</td> <td style='{$tr1Style}'>Total</td> <td style='{$tr1Style}'>Last Strike</td> </tr>"; // break the top part of the table // create your loop foreach($tid as $k => $v){ // pass in storm intensity for current storm switch(strtolower(trim($tintensity[$k]))) { case 'weak': $stormIntensity = 'rgb(0, 255, 0)'; break; case 'moderate': $stormIntensity = 'rgb(255, 255, 0)'; break; case 'strong': $stormIntensity = 'rgb(255, 102, 0)'; break; case 'severe': $stormIntensity = 'rgb(198, 1, 204)'; break; } // replace default color with $stormIntensity $intCat = str_replace('color: #FFF;', "color: $stormIntensity;", $tr2Style); // pass in storm intensity for current storm switch(strtolower(trim($ttrend[$k]))) { case 'weakening': $stormTrend = 'rgb(0, 255, 0)'; break; case 'steady': $stormTrend = 'rgb(255, 255, 0)'; break; case 'intensifying': $stormTrend = 'rgb(255, 0, 0)'; break; } // replace default color with $stormIntensity $treCat = str_replace('color: #FFF;', "color: $stormTrend;", $tr2Style); $tracreport .= "<tr> <td style='{$intCat}'>" . $tid[$k] . "</td> <td style='{$tr2Style}'>" . $tdtime[$k] . "</td> <td style='{$tr2Style}'>" . $tdirection[$k] . "°</td> <td style='{$tr2Style}'>" . $tdistance[$k] . " miles</td> <td style='{$intCat}'>" . $tintensity[$k] . "</td> <td style='{$treCat}'>" . $ttrend[$k] . "</td> <td style='{$tr2Style}'>" . $tcurraterate[$k] . "</td> <td style='{$tr2Style}'>" . $tpeakrate[$k] . "</td> <td style='{$tr2Style}'>" . $ttotalstrikes[$k] . "</td> <td style='{$tr2Style}'>" . $tactivity[$k] . "</td> </tr>"; } // close your loop // finish your table $tracreport .= "</table> </td> </tr> </table></div>"; } echo $tracreport; ?> Any advice or suggestions would be great. I am sure it is something really simple that I am just overlooking. It has been a few months since I have worked with PHP. -Thanks
  7. BINGO!!! Thank you so much for your help. That is exactly what I am needing. Now on to the other two minor issues and this should be completed.
  8. Thanks for the suggestion it is greatly appreciated It makes complete sense and I didn't even think about adding it in the loop. Unfortunately it still isn't working and it all looks right and the logic makes sense. It wouldn't matter that I am imploding a text file or how I am doing it would it? Something is definitely strange because there are other things I have done in the past that aren't working ether but that is a separate issue. With the suggestion above it causes the text to not appear at all. http://www.mesquiteweather.net/tracreportNS.php <?php // The TRACreportshort takes Nexstorm's full TRACreport and shortens it to a more // managable size for displaying. // // It chops up the vital storm cell info, places it in arrays, and redisplays it as we wish // // Set some default values $measure = "mi"; // km, nm, or mi depending on your Nexstorm measurements // Let's assign the tables some styles $tracTable = "width:100%; margin-top: 15px; background-color:#000; color:#FFF;"; $td1Style = "padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;"; $tr1Style = "background-color:#333; color:#3299cc; font-weight: normal; text-align: center; font-size: .9em;"; $tr2Style = "background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;"; $intStyle = "background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;"; // Load the TRACreport and remove carriage returns, change the word 'no change' to 'steady' $trac = implode('', file('lightning/nexstorm/TRACReport.txt')); $tracnopara = preg_replace( '|\n|', '=', $trac ); $tracnopara = preg_replace( '|No change|', 'Steady', $tracnopara ); $tracnopara = preg_replace( '|/minute|', ' a min', $tracnopara); // Intialize values $tracreport = ""; $tnumber = 0; $alertflag = 0; $tracwarning = ""; // If there aren't any thunderstorms, then say it if (preg_match("/No thunderstorms detected/i", $trac)) { $tracreport = "<table style='{$tracTable}'> <tr> <td style='{$td1Style}'>No nearby thunderstorms detected</td> </tr> </table>"; } else { // If there are thunderstorms, process them, putting them into various arrays // $tnumber[x] is for number of thunderstorms preg_match("/Tracking (.*) thunderstorms/Uis", $tracnopara, $tnumber); // $tid[x] is the ID number of the storm preg_match_all("/Thunderstorm ID (.*) detected/Uis", $tracnopara, $temp); $tid = $temp[1]; // $tdtime[x] is the time detected preg_match_all("/detected (.*)=/Uis", $tracnopara, $temp); $tdtime = $temp[1]; // $tdirection[x] is the direction of the storm preg_match_all("/Storm location bearing (.*) dgr/Uis", $tracnopara, $temp); $tdirection = $temp[1]; // $tdistance[x] is the distance in $measure amounts preg_match_all("/distance (.*) $measure/Uis", $tracnopara, $temp); $tdistance = $temp[1]; //$tintensity[x] is the intensity of the storm preg_match_all("/Intensity class (.*)=/Uis", $tracnopara, $temp); $tintensity = $temp[1]; //$ttrend[x] is the trend of the storm preg_match_all("/Intensity trend (.*)=/Uis", $tracnopara, $temp); $ttrend = $temp[1]; //$tcurraterate[x] Current strikerate preg_match_all("/current strikerate (.*)=/Uis", $tracnopara, $temp); $tcurraterate = $temp[1]; //$tpeakrate[x] Peak strikerate preg_match_all("/peak strikerate (.*)=/Uis", $tracnopara, $temp); $tpeakrate = $temp[1]; //$tpeakrate[x] Total recorded strikes preg_match_all("/total recorded strikes (.*)=/Uis", $tracnopara, $temp); $ttotalstrikes = $temp[1]; //$tactivity[x] Last recorded activity preg_match_all("/recorded activity (.*)=/Uis", $tracnopara, $temp); $tactivity = $temp[1]; // Set working for the header based on number of thunderstorms if ($tnumber[1] == 1){ } else { // Sometimes the TRACreport is empty so we need to say that //$tracreport = "<br />No data currently available or thunderstorms detected.<br/>"; } // This builds each line of text for each thunderstorm // begin your table $tracreport .= "<div id='tracReport'><table style='{$tracTable}'> <tr> <td style='{$td1Style}'> Tracking " . $tnumber[1] . " active thunderstorms</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr style='{$tr1Style}'> <td>Cell ID</td> <td>Tracking Since</td> <td>Bearing</td> <td>Distance</td> <td>Intensity</td> <td>Trend</td> <td>Current Rate</td> <td>Peak Rate</td> <td>Total</td> <td>Last Strike</td> </tr>"; // break the top part of the table // create your loop foreach($tid as $k => $v){ // pass in storm intensity for current storm switch($tintensity[$k]) { case 'weak': $stormIntensity = 'rgb(255, 255, 0)'; break; case 'moderate': $stormIntensity = 'rgb(255, 102, 0)'; break; case 'strong': $stormIntensity = 'rgb(255, 0, 0)'; break; case 'severe': $stormIntensity = 'rgb(217, 0, 126)'; break; } // replace default color with $stormIntensity $intStyleCat = str_replace('color: #FFF;', "color: $stormIntensity;", $intStyle); $tracreport .= "<tr> <td style='{$tr2Style}'>" . $tid[$k] . "</td> <td style='{$tr2Style}'>" . $tdtime[$k] . "</td> <td style='{$tr2Style}'>" . $tdirection[$k] . " °</td> <td style='{$tr2Style}'>" . $tdistance[$k] . " miles</td> <td style='{$intStyleCat}'>" . $tintensity[$k] . "</td> <td style='{$tr2Style}'>" . $ttrend[$k] . "</td> <td style='{$tr2Style}'>" . $tcurraterate[$k] . "</td> <td style='{$tr2Style}'>" . $tpeakrate[$k] . "</td> <td style='{$tr2Style}'>" . $ttotalstrikes[$k] . "</td> <td style='{$tr2Style}'>" . $tactivity[$k] . "</td> </tr>"; } // close your loop // finish your table $tracreport .= "</table> </td> </tr> </table></div>"; } echo $tracreport; ?>
  9. I don't need CSS lessons. I am fully aware how CSS works. I have a degree in Web Development and have been doing it for 10+ years. Besides what your suggesting I am not doing. Did you not look at the full cleaned up code I posted? I don't think you're reading or looking at anything I am posting before answering. There is a reason I was doing it the way I was doing it and I didn't come here to get critiqued for that as it is irrelevant to my question. I am fully aware of how to use CSS, I am just not that fluent in PHP and what I do know about PHP I have self taught myself so give me a little credit. What color variable are you referring to? I don't have a color variable "$FFF", do you mean #FFF? If so of course #FFF isn't going to have quotes around it. I don't think you understand what "strtolower" does so let me explain it to you which I shouldn't even be doing anyways as it has NOTHING to do with my question other than you wanting to queston why I am doing something when you're not familiar with what it does which you shouldn't even be doing since it irrelevant to my question. Why am I not just creating it in lower case you ask? Because the software that produces and uploads the text file to my server in which I am exploding the data from produces it in CAPS. I have no control over that, that is just how the text file is created from the software and it is uploaded. So if I was just to use that variable that I created to pull that data from the text file it would output it in CAPS. I don't want it in caps. Seeing that there is 4 possible data outputs for that variable it is easier to just use "strtolower" with that variable so that the are in all lower case. So you take the variable that you have created from the preg_match for that data and you use it like strtolower($ttrend) for example, it will now take that data within that variable and make it all lower case when it is outputted. Why? because that is what I want. I want it in lower case and that is the only way to do that since the data source produces it in CAPS which I don't want. So I can't create it in lower case because I have no control on how the data is produced in the text file. Again, irrelevant to my problem. Again, unless you're not looking at the code I am posting or I am not understanding what you are saying but, the var does have a defined value as it is grabbing it from switch which is where var stormintensity is created from to start with. I thankk you for attempting to answer my question but all you're doing is complicating my question and I don't believe you are skilled enough to resolve this issue for me. So please refrain from responding further so those that so have a solution to my problem can offer it without you complicating this post any further with irrelevant questions. -Thanks
  10. It DOES pertain but you are questioning something that WORKS and has nothing to do with what I am trying to do. I posted it as an example of what WORKS vs what DOESN'T vs what I have TRIED. strtolower($tintensity[$k]) is the variable used to populate the data in that cell. "strtolower" is to take the data from the text file and make it all lowercase. [$k] is the loop so each new data has it's own row in the table. I really didn't think I needed to go into detail explaining that as anyone with PHP experience would recognize that as such. Now when I take the variable "$tintensity" and insert it into a switch like this..... $stormIntensity = ''; switch($tintensity) { case 'weak': $stormIntensity = 'rgb(255, 255, 0)'; break; case 'moderate': $stormIntensity = 'rgb(255, 102, 0)'; break; case 'strong': $stormIntensity = 'rgb(255, 0, 0)'; break; case 'severe': $stormIntensity = 'rgb(217, 0, 126)'; } That now creates a new variable called "$stormIntensity" which in theory should take that data depending on what it is and assign a color to it. BUT, when I replace "strtolower($tintensity[$k])" in the loop with the new variable from the switch "strtolower($stormIntensity[$k])" it doesn't work. I did realize AFTER I posted that it needs to be in the styling not in the actual loop. Which I have done here but, it still doesn't work. $intStyle = "background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em; color: ' . $stormIntensity . '"; I agree, and that is what I normally do AFTER I get the look I am going for first and get everything working correctly. Then I go back and clean it up as it is easier and faster for ME that way when I am first putting something together. That might not be what everyone does or recommends but that is what I like to do and it works for me. Everyone has their own way of doing things. I am currently still writing this script so I was posting raw code that I hadn't been cleaned up yet but, since posting it I have cleaned it up. That is irrelevant to my question though. As you can see, I have cleaned it up. Here is the entire code. <?php // The TRACreportshort takes Nexstorm's full TRACreport and shortens it to a more // managable size for displaying. // // It chops up the vital storm cell info, places it in arrays, and redisplays it as we wish // // Set some default values $measure = "mi"; // km, nm, or mi depending on your Nexstorm measurements // Let's assign the tables some styles $tracTable = "width:100%; margin-top: 15px; background-color:#000; color:#FFF;"; $td1Style = "padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;"; $tr1Style = "background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;"; $tr2Style = "background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;"; $intStyle = "background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em; color: ' . $stormIntensity . '"; // Load the TRACreport and remove carriage returns, change the word 'no change' to 'steady' $trac = implode('', file('lightning/nexstorm/TRACReport.txt')); $tracnopara = preg_replace( '|\n|', '=', $trac ); $tracnopara = preg_replace( '|No change|', 'Steady', $tracnopara ); $tracnopara = preg_replace( '|/minute|', ' a min', $tracnopara); // Intialize values $tracreport = ""; $tnumber = 0; $alertflag = 0; $tracwarning = ""; // If there aren't any thunderstorms, then say it if (preg_match("/No thunderstorms detected/i", $trac)) { $tracreport = "<table style='{$tracTable}'> <tr> <td style='{$td1Style}'>No nearby thunderstorms detected</td> </tr> </table>"; } else { // If there are thunderstorms, process them, putting them into various arrays // $tnumber[x] is for number of thunderstorms preg_match("/Tracking (.*) thunderstorms/Uis", $tracnopara, $tnumber); // $tid[x] is the ID number of the storm preg_match_all("/Thunderstorm ID (.*) detected/Uis", $tracnopara, $temp); $tid = $temp[1]; // $tdtime[x] is the time detected preg_match_all("/detected (.*)=/Uis", $tracnopara, $temp); $tdtime = $temp[1]; // $tdirection[x] is the direction of the storm preg_match_all("/Storm location bearing (.*) dgr/Uis", $tracnopara, $temp); $tdirection = $temp[1]; // $tdistance[x] is the distance in $measure amounts preg_match_all("/distance (.*) $measure/Uis", $tracnopara, $temp); $tdistance = $temp[1]; //$tintensity[x] is the intensity of the storm preg_match_all("/Intensity class (.*)=/Uis", $tracnopara, $temp); $tintensity = $temp[1]; //$ttrend[x] is the trend of the storm preg_match_all("/Intensity trend (.*)=/Uis", $tracnopara, $temp); $ttrend = $temp[1]; //$tcurraterate[x] Current strikerate preg_match_all("/current strikerate (.*)=/Uis", $tracnopara, $temp); $tcurraterate = $temp[1]; //$tpeakrate[x] Peak strikerate preg_match_all("/peak strikerate (.*)=/Uis", $tracnopara, $temp); $tpeakrate = $temp[1]; //$tpeakrate[x] Total recorded strikes preg_match_all("/total recorded strikes (.*)=/Uis", $tracnopara, $temp); $ttotalstrikes = $temp[1]; //$tactivity[x] Last recorded activity preg_match_all("/recorded activity (.*)=/Uis", $tracnopara, $temp); $tactivity = $temp[1]; // Set working for the header based on number of thunderstorms if ($tnumber[1] == 1){ } else { // Sometimes the TRACreport is empty so we need to say that //$tracreport = "<br />No data currently available or thunderstorms detected.<br/>"; } $stormIntensity = ''; switch($tintensity) { case 'weak': $stormIntensity = 'rgb(255, 255, 0)'; break; case 'moderate': $stormIntensity = 'rgb(255, 102, 0)'; break; case 'strong': $stormIntensity = 'rgb(255, 0, 0)'; break; case 'severe': $stormIntensity = 'rgb(217, 0, 126)'; } // This builds each line of text for each thunderstorm // begin your table $tracreport .= "<div id='tracReport'><table style='{$tracTable}'> <tr> <td style='{$td1Style}'> Tracking " . $tnumber[1] . " active thunderstorms</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='{$tr1Style}'>Cell ID</td> <td style='{$tr1Style}'>Tracking Since</td> <td style='{$tr1Style}'>Bearing</td> <td style='{$tr1Style}'>Distance</td> <td style='{$tr1Style}'>Intensity</td> <td style='{$tr1Style}'>Trend</td> <td style='{$tr1Style}'>Current Rate</td> <td style='{$tr1Style}'>Peak Rate</td> <td style='{$tr1Style}'>Total</td> <td style='{$tr1Style}'>Last Strike</td> </tr>"; // break the top part of the table // create your loop foreach($tid as $k => $v){ $tracreport .= "<tr> <td style='{$tr2Style}'>" . $tid[$k] . "</td> <td style='{$tr2Style}'>" . $tdtime[$k] . "</td> <td style='{$tr2Style}'>" . $tdirection[$k] . " °</td> <td style='{$tr2Style}'>" . $tdistance[$k] . " miles</td> <td style='{$intStyle}'>" . strtolower($tintensity[$k]) . "</td> <td style='{$tr2Style}'>" . trim(strtolower($ttrend[$k])) . "</td> <td style='{$tr2Style}'>" . $tcurraterate[$k] . "</td> <td style='{$tr2Style}'>" . $tpeakrate[$k] . "</td> <td style='{$tr2Style}'>" . $ttotalstrikes[$k] . "</td> <td style='{$tr2Style}'>" . trim(strtolower($tactivity[$k])) . "</td> </tr>"; } // close your loop // finish your table $tracreport .= "</table> </td> </tr> </table></div>"; } echo $tracreport; ?> Which in turn produces this..... http://www.mesquiteweather.net/tracreportNS.php Now what I am wanting to do is take the text that is under the "Intensity" and "Trend" column and assign colors to them depending on what the text is. I.E. Weak = green, Moderate = yellow etc, etc. BUT, when I insert the variable from the switch into the styling for that row it doesn't change the text color. So, what am I missing or doing wrong? I have done this many times in the past and it has worked just fine. Just not sure what I am overlooking and why it is not working this time Does that explain things better?
  11. strtolower takes the data and makes it all lower case. Ignore $stormintensity[$k] that is part of the loop. I posted it as an example as that is the variable I use to populate that cell which works fine. I think you maybe be looking at the wrong part of my code or I didn't explain it correctly and you're not understanding it. I did dawn on me after i posted that I need to be adding it to the style but it still isn't working. <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em; color:" . $stormIntensity . "'>" . strtolower($tintensity[$k]) . "</td> Here is an example. Under "Intensity" and "Trend" I want to change the text a certain color depending on what that text is. http://www.mesquiteweather.net/tracreportNS.php If I need to post my entire code I can if that would be easier. I was just trying to streamline it and post only what was relevant.
  12. Hello, I am not good at explaining things but I will do my best. I have this small script that reads this text file then displays the data in a table. What I am trying to do is on one of the table cells the text that is displayed in I want the text to be a certain color depending on what it says. I.E. weak = yellow, moderate = orange and so on. I have this snippet of code I have used in the past to do this but for some reason when I plug the variable into the table the data doesn't display. This is the snipped that reads the text file to get the data and works perfect. //$tintensity[x] is the intensity of the storm preg_match_all("/Intensity class (.*)=/Uis", $tracnopara, $temp); $tintensity = $temp[1]; Then I display it in the table like this and it works fine. <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td> Now this is how I am trying to assign the color to the text which as worked fine for me in the past. $stormIntensity = ''; switch($tintensity) { case 'weak': $stormIntensity = 'rgb(255, 255, 0)'; break; case 'moderate': $stormIntensity = 'rgb(255, 102, 0)'; break; case 'strong': $stormIntensity = 'rgb(255, 0, 0)'; break; case 'severe': $stormIntensity = 'rgb(217, 0, 126)'; } But when I try to use it in the cell like this replacing the "$tintensity" that is normally there that displays the data then nothing shows. <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($stormIntensity[$k]) . "</td> I have tried it like this and no luck ether <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $stormIntensity[$k] . "</td> What am I missing or doing wrong? It has been a few months since I have had to work with PHP so still trying to remember things. -Thanks
  13. Ok I found the issue. In the inside table the is an id like this "id='tracReport'". In the head of the page I am including this in I have this small jquery script that refreshes the table data. <script type="text/javascript"> $(document).ready(function(){ refreshTable(); }); function refreshTable(){ $('#tracReport').load('tracreportNS.php', function(){ setTimeout(refreshTable, 30000); }); } </script> So I just moved the ID that references that script to the outer table and it is working correctly now.
  14. I didn't show the code for how I am including it because it was stated in my OP. It is just a simple include statement. Also for simplicity since the page it is included in is long and has other code in it not relevant. The script is being called like so. <?php include('tracreportNS.php'); ?> Like stated in my original post and displayed with a screenshot when you call the script directly in the browser it displays correctly. http://www.mesquiteweather.net/tracreportNS.php I didn't write the initial script. I am just trying to modify it for what I am needing it for as the initial script was written for something else that it being used for in another page. It's not inside the foreach loop because then it will duplicate every time there is new row of data. It is in the initial array at the beginning of the code that parses the text file to create the variable. What do I need to do to fix this? -Thanks
  15. Hello, I am having a small issue which I think is just a simple problem but I can't seem to solve it. I have a small simple script that parses a text file of data sorts it through an array and creates variables to display the data in a table. Problem I am having is when I call the script inside the page for it to be displayed with include statement it is showing duplicate data from a single variable. In this case $tnumber[1]. As you can see from this screen shot it shows "Tracking 1 active thunderstorms" twice. If I call the script directly in the browser it displays it correctly as shown below. So I am not sure as to why when I include the script in my page it shows duplicate data or if there is something I am doing wrong. Here is the code that parses the text file then creates the table to display the data. The variable that is being duplicated is on line 93 but I don't know why. <?php // The TRACreportshort takes Nexstorm's full TRACreport and shortens it to a more // managable size for displaying. // // It chops up the vital storm cell info, places it in arrays, and redisplays it as we wish // // Set some default values $measure = "mi"; // km, nm, or mi depending on your Nexstorm measurements // Load the TRACreport and remove carriage returns, change the word 'no change' to 'steady' $trac = implode('', file('lightning/nexstorm/TRACReport.txt')); $tracnopara = preg_replace( '|\n|', '=', $trac ); $tracnopara = preg_replace( '|No change|', 'Steady', $tracnopara ); // Intialize values $tracreport = ""; $tnumber = 1; $alertflag = 0; $tracwarning = ""; // If there aren't any thunderstorms, then say it if (preg_match("/No thunderstorms detected/i", $trac)) { $tracreport = "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'> <tr> <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'>No nearby thunderstorms detected</td> </tr> </table>"; } else { // If there are thunderstorms, process them, putting them into various arrays // $tnumber[x] is for number of thunderstorms preg_match("/Tracking (.*) thunderstorms/Uis", $tracnopara, $tnumber); // $tid[x] is the ID number of the storm preg_match_all("/Thunderstorm ID (.*) detected/Uis", $tracnopara, $temp); $tid = $temp[1]; // $tdtime[x] is the time detected preg_match_all("/detected (.*)=/Uis", $tracnopara, $temp); $tdtime = $temp[1]; // $tdirection[x] is the direction of the storm preg_match_all("/Storm location bearing (.*) dgr/Uis", $tracnopara, $temp); $tdirection = $temp[1]; // $tdistance[x] is the distance in $measure amounts preg_match_all("/distance (.*) $measure/Uis", $tracnopara, $temp); $tdistance = $temp[1]; //$tintensity[x] is the intensity of the storm preg_match_all("/Intensity class (.*)=/Uis", $tracnopara, $temp); $tintensity = $temp[1]; //$ttrend[x] is the trend of the storm preg_match_all("/Intensity trend (.*)=/Uis", $tracnopara, $temp); $ttrend = $temp[1]; //$tactivity[x] Last recorded activity preg_match_all("/recorded activity (.*)=/Uis", $tracnopara, $temp); $tactivity = $temp[1]; // Set working for the header based on number of thunderstorms if ($tnumber[1] == 1){ } else { // Sometimes the TRACreport is empty so we need to say that $tracreport = "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'> <tr> <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'>No data currently available or thunderstorms detected.</td> </tr> </table>"; } // This builds each line of text for each thunderstorm // begin your table $tracreport .= "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'> <tr> <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'> Tracking " . $tnumber[1] . " active thunderstorms</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td> <table id='tracReport' width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Cell ID</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Tracking Since</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Bearing</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Distance</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Intensity</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Trend</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Last Strike</td </tr>"; // break the top part of the table // create your loop foreach($tid as $k => $v){ $tracreport .= "<tr> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tid[$k] . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdtime[$k] . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdirection[$k] . " °</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdistance[$k] . " miles</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($ttrend[$k])) . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($tactivity[$k])) . "</td> </tr>"; } // close your loop // finish your table $tracreport .= "</table> </table> </td> </tr> </table> </td> </tr> </table>"; } echo $tracreport; ?> -Thanks
  16. I got this sorted.... // begin your table $tracreport .= "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'> <tr> <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'> Tracking " . $tnumber[1] . " active thunderstorms</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td> <table id='tracReport' width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Cell ID</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Tracking Since</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Bearing</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Distance</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Intensity</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Trend</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Last Strike</td </tr>"; // break the top part of the table // create your loop foreach($tid as $k => $v){ $tracreport .= "<tr> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tid[$k] . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdtime[$k] . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdirection[$k] . " °</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdistance[$k] . " miles</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($ttrend[$k])) . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($tactivity[$k])) . "</td> </tr>"; } // close your loop // finish your table $tracreport .= "</table> </table> </td> </tr> </table> </td> </tr> </table>";
  17. Hello, I have a table and I want to only echo a table row when it is populated with data and not the entire table like it is now but I am having a bit of a struggle. Is it even possible to echo just a table row when there is data to be populated in it? This is how it is now. $NStracreport .= "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'> <tr> <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'> Tracking " . $tnumber[1] . " active storm cell</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Cell ID</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Tracking Since</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Bearing</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Distance</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Intensity</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Trend</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Last Strike</td </tr> <tr> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tid[$k] . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdtime[$k] . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdirection[$k] . " °</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdistance[$k] . " miles</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($ttrend[$k])) . "</td> <td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($tactivity[$k])) . "</td> </tr> </table> </table> </td> </tr> </table> </td> </tr> </table> <table border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td></tr></tbody></table>"; This is what I have tried, I only want to add a new table row where the php variables are. $tracreport = $tracreport . "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'> <tr> <td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'> Tracking " . $tnumber[1] . " active storm cell</td> </tr> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td> <table width='100%' cellpadding='0' cellspacing='0'> <tr> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Cell ID</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Tracking Since</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Bearing</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Distance</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Intensity</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Trend</td> <td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Last Strike</td </tr>" $tracreport .= "<tr>\n"; $tracreport .= "<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{$tid[$k]}</td>\n"; $tracreport .= "<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{$tdtime[$k]}</td>\n"; $tracreport .= "<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{$tdirection[$k]} °</td>\n"; $tracreport .= "<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{$tdistance[$k]} miles</td>\n"; $tracreport .= "<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{strtolower($tintensity[$k])}</td>\n"; $tracreport .= "<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{trim(strtolower($ttrend[$k]))}</td>\n"; $tracreport .= "<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>{trim(strtolower($tactivity[$k]))}</td>\n"; $tracreport .= "</tr>\n"; "</table> </table> </td> </tr> </table> </td> </tr> </table> <table border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7' /></td></tr></tbody></table>"; -Thanks
  18. Ah yeah thanks! I tried that previously but after looking at it when you did it I forgot to remove the ; from the end when I did it when that wasn't actually the end of the code and should have been removed. DOAH! Thanks!
  19. Hello all, I am having trouble doing something I am familiar with and do all the time but for some reason it is not working in this instance. I have tried many different combinations to echo the date in a table cell. The problem is NOT with the php for the date as I am familiar with date formating. Problem I am having is it is not showing up when I echo and it gives me a parsing error. I have tried it many different ways. With and without double quotes, with and without single quotes, without quotes all together. without single quotes before and after like it is now. Whatever I try it just doesn't want to echo the date. I am not sure what I am missing. Maybe I just need an extra set up eyes. I know this is a really simple issue I am just having a brain fart. This is the actual line. <td style="font-size: 100%;"><b>Weather History for' echo date("D M jS"); '</b></td> This is a snippet from where the code is from. // FULL HISTORY TABLE $fullHistory = ' <!-- Start Weather History --> <div class="NWSround"> <table width="640px" text-align="center" cellpadding="0" cellspacing="0" style="margin:4px 11px 0px 11px;"> <tr> <td style="font-size: 100%;"><b>Weather History for' echo date("D M jS"); '</b></td> </tr> <tr> <td> </td> </tr>'; $yearCount = count($historicalData); // count keys in the array for ($i = 0; $i < $yearCount; $i++){ // for each key, print the date and description $fullHistory .= " <tr>\n"; $fullHistory .= " <td style=\"text-align:justify; font-size: 12px;\">\n"; $fullHistory .= $historicalData[$i]."<br /><br />\n"; $fullHistory .= " </td>\n"; $fullHistory .= " </tr>\n"; } $fullHistory .= ' <tr> <td> <span style="font-size: 9px;">'.$credited.'</span> </td> </tr> </table> </div> <table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td><img alt="" src="images/1pixel.gif" border="0" height="7" width="7"></td><td class="shadow-mid" width="100%"><img alt="" src="images/1pixel.gif" border="0" height="7" width="7"></td><td><img alt="" src="images/1pixel.gif" border="0" height="7" width="7"></td></tr></tbody></table> '.$notes.'<!-- End Weather History --> ';
  20. I got it figured out. Here is what I did in case anyone is looking for something like this. <?php // Load the XML file to read and parse if (file_exists('mesquite.xml')) { $xml = simplexml_load_file('mesquite.xml'); // grab current date/time $pubTime = date("c T"); // Show the RSS header information $rss_output .= "<?xml version='1.0' encoding='iso-8859-1'?>\n"; $rss_output .= "<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom'>\n"; $rss_output .= "<!-- version 1.00 - 13-Jun-2013 -->"; $rss_output .= "<channel>\n"; $rss_output .= "<title>Mesquite Area Storm Reports</title>\n"; $rss_output .= "<description>Courtesy of Mesquite Weather</description>\n"; $rss_output .= "<language>en-us</language>\n"; $rss_output .= "<copyright>Mesquite Weather</copyright>\n"; $rss_output .= "<pubDate>$pubTime</pubDate>\n"; $rss_output .= "<ttl>15</ttl>\n"; $rss_output .= "<lastBuildDate>$pubTime</lastBuildDate>\n"; $rss_output .= "<image>\n"; $rss_output .= "<url>http://www.mesquiteweather.net/images/App_75_x_75.png</url>\n"; $rss_output .= "<width>75</width>\n"; $rss_output .= "<height>75</height>\n"; $rss_output .= "</image>\n"; // Parse the XML and set the variables foreach($xml->reports as $reports){ $name = $reports->name; $location = $reports->location; $report = $reports->report; $description = $reports->description; $timestamp = $reports->timestamp; // Display the RSS entries $rss_output .= "<item>\n"; $rss_output .= "<title>$report</title>\n"; $rss_output .= "<pubDate>$timestamp</pubDate>"; $rss_output .= "<link>http://www.mesquiteweather.net/wxmesqLSR.php</link>\n"; $rss_output .= "<description>Location: $location - Reported by: $name - Description: $description</description>\n"; $rss_output .= "</item>\n"; } } $rss_output .= "</channel>\n"; $rss_output .= "</rss>"; // Save RSS File file_put_contents('mesquite.rss', $rss_output); ?>
  21. It wouldn't let me edit my last post. So here is the current code I have and it seems to be working great. Only problem is it's not saving to a new file which should be mesquite.rss that is defined at the bottom. What am I missing or doing wrong? -Thanks <?php // Load the XML file to read and parse if (file_exists('mesquite.xml')) { $xml = simplexml_load_file('mesquite.xml'); // grab current date/time $pubTime = date("c T"); // Show the RSS header information echo "<?xml version='1.0' encoding='iso-8859-1'?>"; echo "<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom'>"; echo "<!-- version 1.00 - 10-Jun-2012 -->"; echo "<channel>"; echo "<title>Mesquite Area Storm Reports</title>"; echo "<description>Courtesy of Mesquite Weather</description>"; echo "<language>en-us</language>"; echo "<copyright>Mesquite Weather</copyright>"; echo "<pubDate>$pubTime</pubDate>"; echo "<ttl>15</ttl>"; echo "<lastBuildDate>$pubTime</lastBuildDate>"; echo "<image>"; echo "<url>http://www.mesquiteweather.net/images/App_75_x_75.png</url>"; echo "<width>75</width>"; echo "<height>75</height>"; echo "</image>"; // Parse the XML and set the variables foreach($xml->reports as $reports){ $name = $reports->name; $location = $reports->location; $report = $reports->report; $description = $reports->description; $timestamp = $reports->timestamp; // Display the RSS entries echo "<item>\n"; echo "<title>$report</title>\n"; echo "<pubDate>$timestamp</pubDate>"; echo "<link>http://www.mesquiteweather.net/wxmesqLSR.php</link>\n"; echo "<description>Location: $location - Reported by: $name - Description: $description</description>\n"; echo "</item>\n"; } } echo "</channel></rss>"; // Save RSS File $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $doc->preserveWhiteSpace = true; $doc->loadXML($xml->asXML(), LIBXML_NOBLANKS); $doc->save('mesquite.rss'); ?>
  22. Ok I have solved one of my issues and I am able to display multiple entries now. The only issue I have is it doesn't save it as a new file, in this case mesquite.rss the I have to call the actually script in order to view the rss feed. <?php if (file_exists('mesquite.xml')) { $xml = simplexml_load_file('mesquite.xml'); echo "<?xml version='1.0' encoding='iso-8859-1'?>"; echo "<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom'>"; echo "<!-- version 1.00 - 10-Jun-2012 -->"; echo "<channel>"; echo "<title>Mesquite Area Storm Reports</title>"; echo "<link>/</link>"; echo "<description>Courtesy of Mesquite Weather</description>"; echo "<language>en-us</language>"; echo "<generator>RSS feed version 1.00 - 10-Jun-2012</generator>"; echo "<copyright>Mesquite Weather</copyright>"; echo "<pubDate>2013-06-12T14:54:05 CDT</pubDate>"; echo "<ttl>15</ttl>"; echo "<lastBuildDate>2013-06-12T14:54:05 CDT</lastBuildDate>"; echo "<image>"; echo "<url>http://www.mesquiteweather.net/images/App_75_x_75.png</url>"; echo "<width>75</width>"; echo "<height>75</height>"; echo "</image>"; foreach($xml->reports as $reports){ $name = $reports->name; $location = $reports->location; $report = $reports->report; $description = $reports->description; $timestamp = $reports->timestamp; echo "<item>\n"; echo "<title>$report</title>\n"; echo "<link>http://www.mesquiteweather.net/wxmesqLSR.php</link>\n"; echo "<description>Location: $location - $timestamp - Reported by: $name - Description: $description</description>\n"; echo "</item>\n"; } } echo "</channel></rss>"; $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $doc->preserveWhiteSpace = true; $doc->loadXML($xml->asXML(), LIBXML_NOBLANKS); $doc->save('mesquite.rss'); ?>
  23. So I have been trying some things and I almost have this. It's very ugly as I really can't find anything related to exactly what I am trying to do. So I am sure there is probably an cleaner way to do this. This is the code I have now that creates an rss feed. Only two problems with it. 1. It only displays one entry from the XML file. 2. It doesn't save it as a new file I.E. in this case mesquite.rss. Now I can call the script directly in the browser and it looks right with the exception of the two problems above. http://www.mesquiteweather.net/xml/process_copy1.php Here is the code to produce this. <?php if (file_exists('mesquite.xml')) { $xml = simplexml_load_file('mesquite.xml'); foreach($xml->reports as $reports){ $name = $reports->name; $location = $reports->location; $report = $reports->report; $description = $reports->description; $timestamp = $reports->timestamp; } echo "<?xml version='1.0' encoding='iso-8859-1'?> <rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom'> <!-- version 1.00 - 10-Jun-2012 --> <channel> <title>Mesquite Area Storm Reports</title> <link>/</link> <description>Courtesy of Mesquite Weather</description> <language>en-us</language> <generator>RSS feed version 1.00 - 10-Jun-2012</generator> <copyright>Mesquite Weather</copyright> <pubDate>2013-06-12T14:54:05 CDT</pubDate> <ttl>15</ttl> <lastBuildDate>2013-06-12T14:54:05 CDT</lastBuildDate> <image> <url>http://www.mesquiteweather.net/images/App_75_x_75.png</url> <width>75</width> <height>75</height> </image>"; echo "<item> <title>$report</title> <link>http://www.mesquiteweather.net/wxmesqLSR.php</link> <description>Location: $location - $timestamp - Reported by: $name - Description: $description</description> </item>"; } echo "</channel></rss>"; $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $doc->preserveWhiteSpace = true; $doc->loadXML($xml->asXML(), LIBXML_NOBLANKS); $doc->save('mesquite.rss'); ?> Any ideas or suggestions? -Thanks
  24. Correct, I understand I can use SimpleXML to parse it as that is what I planned to do as the current XML file is parsed with SimpleXML to display the data on a HTML page. What I am a little confused on is the required elements for RSS are not the same as the elements in the XML file. I have been unable to locate anything that describes how to read and XML file and format it to an RSS feed. So it needs to read the XML file then format it as RSS then save it as RSS. This is the php script I use to create the XML file from my HTML form. <?php if (isset($_POST['lsr-submit'])) { header('Location: http://www.mesquiteweather.net/wxmesqLSR.php'); } $str = '<?xml version="1.0" encoding="UTF-8"?><entrys></entrys>'; $xml = false;if(file_exists('mesquite.xml')) $xml = simplexml_load_file('mesquite.xml'); if(!$xml) $xml = simplexml_load_string('<entrys/>'); $name = $_POST['name']; $location = $_POST['location']; $report = $_POST['report']; $description = $_POST['desc']; $fname = htmlentities($fname, ENT_COMPAT, 'UTF-8', false); $lname = htmlentities($lname, ENT_COMPAT, 'UTF-8', false); $location = htmlentities($location, ENT_COMPAT, 'UTF-8', false); $report = htmlentities($report, ENT_COMPAT, 'UTF-8', false); $description = htmlentities($description, ENT_COMPAT, 'UTF-8', false); $reports = $xml->addChild('reports'); $reports->addChild('timestamp', date("D M jS g:i a",time())); $reports->addChild('name', $name); $reports->addChild('location', $location); $reports->addChild('report', $report); $reports->addChild('description', $description); $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $doc->preserveWhiteSpace = true; $doc->loadXML($xml->asXML(), LIBXML_NOBLANKS); $doc->save('mesquite.xml'); ?> So does anyone have any suggestions or can point me in the direction of a tutorial that describes how to read an XML file to create an XML feed? I think I am making this hard than it is which I know should be a really simple process. -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.