Jump to content

drexnefex

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://nwbroweather.com

Profile Information

  • Gender
    Not Telling

drexnefex's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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!
×
×
  • 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.