Jump to content

drexnefex

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Everything posted by drexnefex

  1. Novice in way over head here! Created a mySQL db. populated with a bunch of data in one table. have a simple file based login/authentication system that i've setup. now im looking to establish some sort of process where specific users login and see specific fields. something like if userX see fields 1,2,4. if userY see fields 1,2,3. SQL statements?? im completely lost on the logic how that might be best created. hoping someone might point me in right direction...been spinning wheels.
  2. ah. that did it... thanks Salathe
  3. getting an "Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in...." error on the following site: http://nwsurfing.com/buoy.php i haven't changed anything in either of the two files that runs this page so im stumped. [attachment deleted by admin]
  4. Here's the code for attempt1 <pre> <?php $nwac[0] = OSOALP; $nwac[1] = OSOCMT; $nwac[2] = OSOHUR; $nwac[3] = OSOMHM; $nwac[4] = OSOMSR; $nwac[5] = OSOMTB; $nwac[6] = OSOSK9; $nwac[7] = OSOWPS; for($counter = 0; $counter < 7; $counter += 1) { $data = curl_init(); // set URL and other appropriate options curl_setopt($data, CURLOPT_URL, "http://nwac.us/products/$nwac[$counter]"); curl_setopt($data, CURLOPT_RETURNTRANSFER, true); curl_setopt($data, CURLOPT_TIMEOUT, 30); // grab URL $output = curl_exec($data); #curl_exec($data); curl_close($data); ### Get the header. preg_match('%MM/DD.+?(?=-{2,})%s', $output, $matches); print_r($matches); ### Separate the metadata from the data; if you don't, ### the date "1-9-2007" will be picked up as data. ### The separator is the line of hyphens. $data_pieces = preg_split('/^-{2,}\r?$/m', $output); $data_area = array_pop($data_pieces); ### Get the rows. preg_match_all('%^[-.\d ]+\r?$%m', $data_area, $matches); print_r($matches); ### Last row. print_r(array_pop($matches[0])); } //Part of array above. ?> </pre> And attempt2 <pre> <?php $nwac[0] = OSOALP; $nwac[1] = OSOCMT; $nwac[2] = OSOHUR; $nwac[3] = OSOMHM; $nwac[4] = OSOMSR; $nwac[5] = OSOMTB; $nwac[6] = OSOSK9; $nwac[7] = OSOWPS; for($counter = 0; $counter < 7; $counter += 1) { $raw = file("http://nwac.us/products/$nwac[$counter]"); $data = split("\t", $raw[30]); echo print_r($data); } ?> </pre>
  5. Hello - I am trying to grab a series of unformatted text files, parse them, organize specific parts of them into arrays, then dump those arrays into a table in specific locations. I've made a few attempts...at least at the grabbing/parsing part, but have no clue how to proceed. Attempt1 - http://nwbroweather.com/weather/nwac.php Attempt2 - http://nwbroweather.com/weather/nwac2.php Here's a link to one of the unformatted txt files im trying to work with: http://nwac.us/products/OSOSK9 There's going to be about 8 of these files that i'm going to want to work with. They are not all structured the same. The data in the text file contains temperatures at a few different elevations (among other things). I'd like to grab the most recent temps and dump them into a table. The most recent temps are located at the bottom of the data file. Table would look something like this: LocationBaseTempMidTempTopTemp Site X30°24°19° Any ideas would be greatly appreciated. Is there a better to accomplish this task than with PHP? Is this even possible given the unstructured target data? Thanks.
  6. sweet! thanks, that did it. thanks again for you help. -drexnefex
  7. Jason - thanks again. I uploaded your php v.4 script to my webserver...got the following error: Fatal error: Call to undefined function: array() in /..../phpBuoy.php on line 373 any idea what's causing that one? -drexnefex
  8. damn...i just noticed that my web host is running php4.4.6. i tried the script on a test server at my work (not the same machine that host my website) which is running the latest version of PHP...and it works great. Any chance this could be tweaked to run on a php4 machine? -S
  9. hey Jason! thanks for the reply. thanks for taking the time to tinker with this stuff. it's way over my head. I tried the attached scripts....they all errored out. got the following error: Fatal error: Call to undefined function: array_combine() in ....../phpBuoy.php on line 448 wow, you really modified the code. im super curious to see how it works. any ideas as to what's going wrong on my end?
  10. well. that fix at least got rid of the error....browse just keeps chugging though. i was getting CPU exceedance warnings though. so something is wrong. here's something that might be an issue. the header rows, both of them, are references for what type of data and what unit of measurement is in that particular column. example: the $WVHT refers to wave height. the unit of measurement is in meters. later on in the script there is some conversion code (meters to feet) that reference this variable $WVHT. so here's my new question: is skipping over the two header rows which contain the type and unit measurement of data eliminate that information getting passed to the meters to feet conversion part of this script? something is causing this thing to chug forever.... here's the latest version, complete with your (C4) advice implemented. anything stand out that might be causing this to fail? [attachment deleted by admin]
  11. Thanks for the reply C4. What does the regex '/\s+/' look for? What is the difference between your suggestion and the original regex: '/[\s,]+/' ? I inserted your snippet into the script but got a parse error on this line (pretty sure it's the bracket causing the problem): if(preg_match('/^#/', $line) { I tried a bunch of different combinations of moving that bracket around but kept getting parse errors. Any ideas what would cause the error? Thanks for taking the time.
  12. hello. i have a script that parses text files containing NOAA Buoy data. recently NOAA changed the format of the header row contained in the text files. as a result the script broke. im not the author of the script though i've heavily customized it by stumbling my way through php and regex's. i've been tinkering with this for a while now and am completely stumped. the script is attached. here's the old header that the script read: YYYY MM DD hh mm WD WSPD GST WVHT DPD APD MWD BARO ATMP WTMP DEWP VIS PTDY TIDE and the new format (includes an extra line) #YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS PTDY TIDE #yr mo dy hr mn degT m/s m/s m sec sec degT hPa degC degC degC mi hPa ft here's a link to one of the files that the script would parse: http://www.ndbc.noaa.gov/data/realtime2/44004.txt can anyone point me in the right direction? [attachment deleted by admin]
  13. effigy - thanks for the quick reply and much thanks for the code. on my end your code works great.  it's splitting out the header row from the body rows as it should but it's returning the entire set of rows rather than just the last complete row. i've added a curl variable and an array that looks at a series of files.... any idea what is preventing this from returning just the last complete row in each table?  im assuming it's the match pattern.... [code]<pre> <?php $nwac[0] = OSOALP; $nwac[1] = OSOSNO; $nwac[2] = OSOMTB; $nwac[3] = OSOSK9; $nwac[4] = OSOCMG; $nwac[5] = OSOMHM; $nwac[6] = OSOPVC; $nwac[7] = OSOWPS; for($counter = 0; $counter < 7; $counter += 1) { $data = curl_init(); // set URL and other appropriate options curl_setopt($data, CURLOPT_URL, "http://www.nwac.us/products/$nwac[$counter]"); curl_setopt($data, CURLOPT_RETURNTRANSFER, true); curl_setopt($data, CURLOPT_TIMEOUT, 30); // grab URL $output = curl_exec($data); #curl_exec($data); curl_close($data); ### Get the header. preg_match('%MM/DD.+?(?=-{2,})%s', $output, $matches); print_r($matches); ### Separate the metadata from the data; if you don't, ### the date "1-9-2007" will be picked up as data. ### The separator is the line of hyphens. $data_pieces = preg_split('/^-{2,}\r?$/m', $output); $data_area = array_pop($data_pieces); ### Get the rows. preg_match_all('%^[-.\d ]+\r?$%m', $data_area, $matches); print_r($matches); ### Last row. print_r(array_pop($matches[0])); }  //Part of array above. ?> </pre>[/code]
  14. Hello all - I am looking to use CURL, preg_match, and a regex function to pull specific data from unformatted text files. Based on how these files are structured...i dont have the slightest clue how to create a regex pattern. Here is one of the files: [code]1-9-2007 Northwest Weather and Avalanche Center Alpental Ski Area, Washington Wind instruments unheated and may rime Wind speed not accurate, Precip gage under-recording 5,6 Jan MM/DD  Hour  Temp  Temp  Temp    RH    RH  Wind  Wind  Wind  Hour Total  24Hr Total         PST    F    F    F    %    %  Avg  Max  Dir. Prec. Prec.  Snow  Snow             5400' 4300' 3120' 3120' 5400' 5530' 5530' 5530' 3120' 3120' 3120' 3120' ------------------------------------------------------------------------------------   1 8  1000    25    28    34    93    98    2    16  258    0    0    -0    96   1 8  1100    25    29    36    87    98    1    15  258    0    0    -0    96   1 8  1200    23    29    36    90    98    2    15  258    0    0    -0    96   1 8  1300    23    28    34    93    98    1    13  258    0    0    0    96   1 8  1400    25    28    34    96    98    1    16  258    0    0    0    97   1 8  1500    26    29    33    99    99    0    13  258    0    0    0    97   1 8  1600    28    29    32  100    99    1    16  259    0    0    0    97   1 8  1700    29    28    32  100  100    2    14  258  .02  .02    0    97   1 8  1800    30    29    32  100  100    0    16  258    0  .02    0    97   1 8  1900    31    30    32  100  100    3    17  258  .02  .04    0    97   1 8  2000    31    31    32  100  100    -1    17  258  .03  .07    0    97   1 8  2100    31    32    32  100  100    1    15  258  .06  .13    0    97   1 8  2200    31    33    32  100  100    3    17  258  .03  .16    0    96   1 8  2300    31    33    33  100  100    2    13  258  .01  .17    0    96   1 9    0    31    33    33  100  100    1    15  258    0  .17    0    96   1 9  100    31    33    33  100  100    2    15  258    0  .17    0    96   1 9  200    31    33    33  100  100    -1    12  258  .01  .18    0    96   1 9  300    31    33    33  100  100    1    16  258    0  .18    0    96   1 9  400    31    34    33  100  100    2    14  258  .01  .19    0    96   1 9  500    30    34    34  100  100    1    13  258    0  .19    0    96   1 9  600    30    33    34  100  100    1    13  258    0  .19    0    95   1 9  700    30    33    34  100  100    2    13  258    0  .19    0    95   1 9  800    30    33    34  100  100    0    13  258    0  .19    0    95   1 9  900    30    34    34  100  100    1    13  259    0  .19    0    95                                                                     .19                                       Page 1 [/code] Source of data:  http://www.nwac.us/products/OSOALP I want the regex to match the 1st 3 header rows of the 'table' and the last row of the 'table.' Essentially what i want to do is extract data from this and a few other similarly structured files and dump it into an html table. I have a handle on the curl part but the regex for this completely boggles my mind. Any ideas?
  15. thanks for the reply. i figured out the problem. the script was parsing a series of txt files on a NOAA gov server.  one of the files (the 1st in my array) isn't being served anymore due the Buoy that was recording wave data having been lost in the big winter storms we've been having out here. i eliminated that from my array, changed my counter and it worked!
  16. Hello - I am getting the following error: Warning: socket_set_timeout(): supplied argument is not a valid stream resource in /testbuoy4.php on line 179. This script was working fine a few days ago and suddenly broke.  I haven't edited the file recently and am completely stumped on why it's broken. Any ideas out there? [code]<? ########### # phpBuoy # ########### # # Version:          1.0.2 # Last modified:    May 28, 2003 # # Author:          Steve Lange - steve@surfimplement.com # Homepage:        http://www.surfimplement.com/phpBuoy/ # # # ################ # LICENSE INFO # ################ # # This file is released under the terms of the # Gnu Public License available for viewing at: # http://www.surfimplement.com/gpl.txt # # Feel free to modify this script as you see fit, # but respect the terms of the license. # # # phpBuoy was created in part with code from # Kalle Kiviaho's Newsbackends script, for # parsing headline files using PHP. You can # check it out at: # http://swamp.chl.chalmers.se/backends/ # # # ###################### # HOW TO USE phpBuoy # ###################### # # phpBuoy is meant to be used as either a PHP # or SSI include file, and of course must be # used on a machine with PHP installed. # # There are a number of user-based customizations # possible, most importantly the buoy station # from which to parse the buoy reports. # Please see below for details. ################################ # START OF USER CUSTOMIZATIONS # ################################ # Go to http://www.ndbc.noaa.gov/ and locate the station number # of the buoy for which you want to get data. Enter that number # below for $, and then provide whatever info you # want display for the station on the output page as $stationName. PRINT <<<HERE <html> <head> <link href="../bro_style2.css" rel="stylesheet" type="text/css"> </head> <body> <table class="table_buoy" border="1" cellpadding="1" cellspacing="0"> <tr> <td>Bouy</td> <td>Date</td> <td>Time (PST)</td> <td>Height (ft)</td> <td>Dom. Period (sec)</td> <td>Water Temp (F)</td> <td>Air Temp (F)</td> <td>Wind Dir.</td> <td>Wind Speed (kts.)</td> <td>Gust (kts.)</td> </tr> HERE; ##  DREXLER NOTE:  the sequence in the "$bouyName" array must be the same as in the "$bouy" array. $buoyName[0] = "Cape Elizabeth"; $buoyName[1] = "Grays Harbor"; $buoyName[2] = "Neah Bay"; $buoyName[3] = "La Perouse Bank"; $buoyName[4] = "Hein Bank"; $buoy[0] = 46041; $buoy[1] = 46211; $buoy[2] = 46087; $buoy[3] = 46206; $buoy[4] = 46088; for($counter = 0; $counter < 5; $counter += 1) { $stationNumber = $buoy[$counter]; $stationName = $buoyName[$counter]; $stationURL = "<a target=_blank class=grey-blue href=http://www.ndbc.noaa.gov/station_page.php?station=$buoy[$counter]>"."$buoyName[$counter]</a>"; # This is the maximum number of readings to display of the buoy data. # If you only want to show the most current reading, leave this unchanged. $maxReadings = 1; # Set the GMT (Greenich Mean Time) offset for the location of the # buoy you are getting reports for. Pacific Standard Time is a -8 hour #offset from GMT; leave this unchanged if that is your desired timezone. $gmtOffset = -8; # 12-hour or 24-hour clock preference # For a 12-hour clock, set $clock = 0; # For a 24-hour clock, set $clock = 1; $clock = 0; # Date format choice. # For U.S.-style dates (MM-DD-YYYY), set $intlDateFormat = 0; # For international-style dates(DD-MM-YYYY), set $intlDateFormat = 1; $intlDateFormat = 0; # Choose metric or English measurements. # For English measurements, set $metric = 0; # For metric measurements, set $metric = 1; $metric = 0; # You can customize the phpBuoy output HTML table, if you want. # If you are using phpBuoy as an nested include file within an existing # table-based page layout, you can probably leave this as-is. # # NOTE: Modify only the HTML code between the PRINT <<<HERE and HERE;! # Make sure that PRINT <<<HERE and HERE; remain. ######################### # END OF CUSTOMIZATIONS # ######################### ################################################################################################ # Really no need to tweak the code from this point down, unless you want to make it better! :) # ################################################################################################ # Location of remote backend file and local cache file # $backend = "http://www.surfimplement.com/include/46063.txt"; $backend = "http://www.ndbc.noaa.gov/data/realtime2/".$buoy[$counter].".txt"; $cache_file = "/tmp/buoydata.".$buoy[$counter].".cache"; # Set timeout duration for establishing a connection # with NDBC's servers...if they're down, we don't want # the script to bomb in graceless fashion. The number # is in seconds. $timeout = 10; # Cache file time-based naming stuff $cache_time = 5; # Buoy readings are only updated every hour so cache the current reading until the next is available $time = split(" ", microtime()); srand((double)microtime()*1000000); $cache_time_rnd = 300 - rand(0, 600); $maxReadings++; # Takes into account the first line of buoy data, which is just column headings like YYYY, DD, HH, ATMP, etc. $numLines = 0; if ( (!(file_exists($cache_file))) || ((filectime($cache_file) + $cache_time - $time[1]) + $cache_time_rnd < 0) || (!(filesize($cache_file))) ) { $url = parse_url($backend); $fp = fsockopen($url['host'], "80", &$errno, &$errstr, $timeout); if(!$fp) { echo "<tr><td>Buoy data currently unavailable - server appears down<br><br><br></td></tr></table>\n"; return; } else { $fpread = @fopen($backend, 'r'); socket_set_timeout($fpread, 3); if(!$fpread) { echo "<tr><td>Buoy data currently unavailable - file could not be loaded<br><br><br></td></tr></table>\n"; return; } else { $fpwrite = @fopen($cache_file, 'w'); if(!$fpwrite) { echo "<tr><td>Buoy data currently unavailable - could not read cache file<br><br><br></td></tr></table>\n\n"; return; } else { $line = fgets($fpread, 1024); while((!feof($fpread)) && ($numLines < $maxReadings)) { $line = eregi_replace("MM","N/A",$line); list($YYYY,$MM,$DD,$hh,$mm,$WD,$WSPD,$GST,$WVHT,$DPD,$APD,$MWD,$BARO,$ATMP,$WTMP,$DEWP,$VIS,$PTDY,$TIDE) = preg_split("/[\s,]+/", $line); # Format the date to MM-DD-YYYY or DD-MM-YYYY if($intlDateFormat == 0) { $formattedDate = $MM."-".$DD."-".$YYYY; } elseif($intlDateFormat != 0) { $formattedDate = $DD."-".$MM."-".$YYYY; } $hh = $hh + $gmtOffset; # Compensate for GMT timezone offset if($clock == 0) { if($hh < 1) { $hour = $hh + 12; # 12hour clock fix $ampm = "PM"; } elseif($hh > 12) { $hour = $hh - 12; # 12hour clock fix $ampm = "PM"; } elseif($hh == 12) { $hour = $hh; $ampm = "PM"; } else { $hour = $hh; $ampm = "AM"; } } elseif($clock != 0) { if($hh < 0) { $hour = $hh + 24; # 24hour clock fix } } # Metric-to-English conversion stuff if($metric == 0) { $windSpeed = "kts."; # "Knots" abbrev. $waveHeight = "ft."; # "Feet" abbrev. $temp = "F"; # "Fahrenheit" abbrev. if($WVHT != "N/A") { $WVHT = round($WVHT * 3.28, 1); # Convert wave height from feet to meters } if($WSPD != "N/A") { $WSPD = round($WSPD * 1.9425, 1); # Convert wind speed from m/s to knots } if($GST != "N/A") { $GST = round($GST * 1.9425, 1); # Convert gust speed from m/s to knots } if($ATMP != "N/A") { $ATMP = round(($ATMP * 1.8) + 32, 1); # Convert air temp from C to F } if($WTMP != "N/A") { $WTMP = round(($WTMP * 1.8) + 32, 1); # Convert water temp from C to F } } elseif($metric != 0) { $windSpeed = "m/s"; # "Meters/Second" abbrev. $waveHeight = "m"; # "Meters" abbrev. $temp = "C"; # "Celcius" abbrev. } # Wind direction conversion stuff if(($WD != "N/A") && ($WD != "WD")) { if(($WD >= 348 && $WD <= 360) || ($WD >= 0 && $WD < 11)) { $WDIR = "N"; } elseif($WD >= 326 && $WD < 348) { $WDIR = "NNW"; } elseif($WD >= 303 && $WD < 326) { $WDIR = "NW"; } elseif($WD >= 281 && $WD < 303) { $WDIR = "WNW"; } elseif($WD >= 258 && $WD < 281) { $WDIR = "W"; } elseif($WD >= 236 && $WD < 258) { $WDIR = "WSW"; } elseif($WD >= 213 && $WD < 236) { $WDIR = "SW"; } elseif($WD >= 191 && $WD < 213) { $WDIR = "SSW"; } elseif($WD >= 168 && $WD < 191) { $WDIR = "S"; } elseif($WD >= 146 && $WD < 168) { $WDIR = "SSE"; } elseif($WD >= 123 && $WD < 146) { $WDIR = "SE"; } elseif($WD >= 101 && $WD < 123) { $WDIR = "ESE"; } elseif($WD >= 78 && $WD < 101) { $WDIR = "E"; } elseif($WD >= 56 && $WD < 78) { $WDIR = "ENE"; } elseif($WD >= 33 && $WD < 56) { $WDIR = "NE"; } elseif($WD >= 11 && $WD < 33) { $WDIR = "NNE"; } else { $WDIR = "N/A"; } } else { $WDIR = "N/A"; } # Print out results of parsing if($numLines >= 1) { fputs($fpwrite, "<tr> <td>$stationURL</td> <td>$MM/$DD</td> <td>$hour:$mm $ampm</td> <td>$WVHT $waveHeight</td> <td>$DPD sec.</td> <td>$WTMP&ordm;$temp</td> <td>$ATMP&ordm;$temp</td> <td>$WD</td> <td>$WSPD $windSpeed</td> <td>$GST $windSpeed</td> </tr>\n"); if($maxLines > 2) { fputs($fpwrite, "<tr><td>&nbsp;</td></tr>\n"); # Spacer break for multiple reading display } } $line = fgets($fpread, 1024); $numLines++; } } fclose($fpread); } fclose($fpwrite); } fclose($fp); } if (file_exists($cache_file)) { include($cache_file); } } PRINT <<<HERE </table> HERE; ?>[/code]
  17. the files are public domain and are readily available for public use. the files are located here:  http://www.ndbc.noaa.gov/data/realtime2/ This page is where i got my script from.  there's an example of the output in the 'Current Santa Barbara Buoy Reports From The NDBC' section.  this script is looking at the same gov server.  why would that work and mine not?  http://www.surfimplement.com/
  18. in checking my server error logs i also got this error roughly when the script stopped functioning properly. [31-Dec-2006 01:23:45] PHP Warning: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]: unable to connect to www.ndbc.noaa.gov:80 in /home/nwbrowea/public_html/weather/testbuoy4.php on line 169 could this have something to do with the date changing to 2007?
  19. the error is this:  Warning: stream_set_timeout(): supplied argument is not a valid stream resource in /xxxxxxxxx/working/testbuoy4.php on line 179
  20. Hello - I have a script that was running fine a few days ago and now it's broken.  I haven't touched the script in quite a while and am stumped as to what could have caused it to break.  I contacted my ISP to see if anything on their end has changed...they said no. This script contacts a NOAA server, parses a text file and spits out a table. file is here:  http://www.nwbroweather.com/working/testbuoy4.php Im getting an error on line 179.  this is line 179-->  stream_set_timeout($fpread, 3); File is attached. Im running PHP 4.4.4 [attachment deleted by admin]
×
×
  • 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.