TFD3 Posted July 16, 2007 Share Posted July 16, 2007 On this page: http://weather.unisys.com/upper_air/skew/skew_KEET.txt displays a bunch of text from top to bottom. Now what im wanting to know if there is a script built that can take just one line of text out of that URL? I have already tried the following but it does not work however no errors are showing up as well. Any thoughts? Here is the code I need help with: The error I think is on line 5 and 6. <?php $lines = file("http://weather.unisys.com/upper_air/skew/skew_KEET.txt"); foreach ($lines as $line) { if (!preg_match("/^;'/",$line)) { $parsed = explode(' ',$line); } } if (!isset($parsed)) { return ; } echo($parsed[2]); ?> Thanks guys! Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/ Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 I also came across this script while searching the forums. This displays the lines that I need but some of the lines I only want like the first half of the text. <?php $file = file("http://weather.unisys.com/upper_air/skew/skew_KEET.txt"); foreach($file as $line) if(strpos($line,"Date: 0") === 0) echo "$line"; ?> Running that code displays Date: 0000Z 16 JUL 07 However I need a way to only show parts of that line like Date: 0000Z 16 JUL Any thoughts on how to only show certain parts of the line and not the whole line? Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299241 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 I've used this script on a actual html doc but made a few changes to steer u in the right way <?php $url= "http://weather.unisys.com/upper_air/skew/skew_KEET.txt"; if($content=file_get_contents($url)){ $lines= explode("\n",$content); //Breaks at each new line; //Your data comes in 17 lines down $table['start'] = 17; $table['end'] = $table['start']+80; //80 lines in table $i = $table['start']; while($i<=$table['end']){ $tabledata .= $lines[$i]; $i++; }//end while //Deal with rest of data with line numbers as needed ?> Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299261 Share on other sites More sharing options...
ss32 Posted July 16, 2007 Share Posted July 16, 2007 cooldude has given you a start. with each line, now, break it up into 4 byte chunks and parse those into numbers. i guess how you want to put it into memory is your preference, whether it be a 2-d array or a custom class. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299263 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 please don't use my script if you don't have rights to use this data. Its considered "stealing" if you don't have the consent of the owner of the .txt file to purge its content for information. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299265 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 please don't use my script if you don't have rights to use this data. Its considered "stealing" if you don't have the consent of the owner of the .txt file to purge its content for information. dont worry me and another user grlevelxstuff.com has permission. however, your script gives me an error Parse error: syntax error, unexpected $end in /home/alabamaw/public_html/beta/soundings/if.php on line 16 however im only seeing 14 lines. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299266 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 i didn't close the if block so close it and you are good i think. Its untested, but i think the line numbers work for that tabular section. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299269 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 i didn't close the if block so close it and you are good i think. Its untested, but i think the line numbers work for that tabular section. ur talking to somebody who has just started doing this. I dont know where or what to add. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299271 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 I added a bit to it to give you some ideas of working. Don't do the 4 byte idea its a good text strucutre work with it in lines, then explode at \t (tabs) and you will be all set: <?php $url= "http://weather.unisys.com/upper_air/skew/skew_KEET.txt"; if($content=file_get_contents($url)){ $lines= explode("\n",$content); //Breaks at each new line; //Your data comes in 17 lines down $keys = explode("\t", $lines[14]); $table['start'] = 17; $table['end'] = $table['start']+80; //80 lines in table $i = $table['start']; while($i<=$table['end']){ $tablerow[$i]['line'] = $lines[$i]; foreach(explode("\t",$lines[$i]) as $value){ $j = 0; $tablerow[$i][$keys[$j]] = $value; $j++; }//end of foreach loop $i++; }//end while //Deal with rest of data with line numbers as needed }//close of if statement ?> edit: changed to assoc keys Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299273 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 if you wanted to use associative keys on that tabular data you can get the keys right off the text file try: $keys = explode("\t", $lines[14]); then in the foreach instead of calling it $tabledata[$i][$j] instead use $tabledata[$i][$keys[$j]] and it will have the associative keys like level, Pres HGHT TEMP etc etc Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299274 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 ok so im not going to be using echo statements? No errors but idk what to add to get the data to show up. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299278 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 This might be too advance if you don't understand what i did. add this to the end <?php echo "<br/><br/><br/>"; print_r($lines); echo "<br/><br/><br/>"; print_r($tablerow); Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299280 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 This might be too advance if you don't understand what i did. add this to the end <?php echo "<br/><br/><br/>"; print_r($lines); echo "<br/><br/><br/>"; print_r($tablerow); Go ahead and take a look at this webpage and tell me if thats what suppose to be showing or not?? LOL Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299282 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 which web page? Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299283 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 This might be too advance if you don't understand what i did. Most stuff I need help with is just the beginning, I usually need to see a working example with data showing and from there I just use trial and error to get what I need. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299284 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 which web page? oh haha http://beta.alabamaweather.org/soundings/if.php Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299285 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 yes. (in short terms) what you looking for (no) This is showing the two arrays we built (i built) Basically you can extract data out of the arrays and use in echo/queries/file writing later on, but if you don't understand that maybe you should get your basics down first. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299287 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 yes. (in short terms) what you looking for (no) This is showing the two arrays we built (i built) Basically you can extract data out of the arrays and use in echo/queries/file writing later on, but if you don't understand that maybe you should get your basics down first. way over my head Can we maybe edit this? <?php $file = file("http://weather.unisys.com/upper_air/skew/skew_KEET.txt"); foreach($file as $line) if(strpos($line,"Date: 0") === 0) echo "$line"; ?> This will display every line that I need however it shows the whole line when I may only need certain words out of that line. Can this be edited to do just that or is it just not possible? Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299290 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 read up on php.net about string functions especially explode and implode those will help you a lot you want to use my method of opening the file and copying it to a variable (its a string so the whole string lib is at your finger tips) then break it into lines as i have done (\n is a line break \t is tab \r is return (not used here, but sometimes part of email headers). Then after its is in line do a print_r($lines); and look through it for what you need then you can work with each line and explode out the data you need. Don't use strpos use implode/explode its a lot better for your needs. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299293 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 asked another person via YIM and he said im going to have to make a subroutine, first routine strip out the sounding data, second routine strip it line by line. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299294 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 which data are you looking for? I had that table data all there for you. Please read on explode/implode and the demos on php.net it will help you understand what to do Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299297 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 read up on php.net about string functions especially explode and implode those will help you a lot you want to use my method of opening the file and copying it to a variable (its a string so the whole string lib is at your finger tips) then break it into lines as i have done (\n is a line break \t is tab \r is return (not used here, but sometimes part of email headers). Then after its is in line do a print_r($lines); and look through it for what you need then you can work with each line and explode out the data you need. Don't use strpos use implode/explode its a lot better for your needs. Using what you wrote can you add a section to get this to show up? "Lifted Index: 1.94 C Risk: Showers probable" I need to see a full working version and then I just go from there on my own. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299299 Share on other sites More sharing options...
cooldude832 Posted July 16, 2007 Share Posted July 16, 2007 I used find and replace to find the line number in the array and then did it off those <?php $url= "http://weather.unisys.com/upper_air/skew/skew_KEET.txt"; if($content=file_get_contents($url)){ $lines= explode("\n",$content); //Breaks at each new line; $lindex[0] = $lines[113]; $lindex[1] = $lines[114]; $lindex[2] = $lines[115]; }//close of if statement //print_r($lines); foreach($lindex as $value){ echo $value."<br/>"; } ?> Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299301 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 I used find and replace to find the line number in the array and then did it off those <?php $url= "http://weather.unisys.com/upper_air/skew/skew_KEET.txt"; if($content=file_get_contents($url)){ $lines= explode("\n",$content); //Breaks at each new line; $lindex[0] = $lines[113]; $lindex[1] = $lines[114]; $lindex[2] = $lines[115]; }//close of if statement //print_r($lines); foreach($lindex as $value){ echo $value."<br/>"; } ?> I think thats the same thing as: <?php $file = file("http://weather.unisys.com/upper_air/skew/skew_KEET.txt"); foreach($file as $line) if(strpos($line,"Date: 0") === 0) echo "$line"; ?> Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299304 Share on other sites More sharing options...
TFD3 Posted July 16, 2007 Author Share Posted July 16, 2007 I used find and replace to find the line number in the array and then did it off those <?php $url= "http://weather.unisys.com/upper_air/skew/skew_KEET.txt"; if($content=file_get_contents($url)){ $lines= explode("\n",$content); //Breaks at each new line; $lindex[0] = $lines[113]; $lindex[1] = $lines[114]; $lindex[2] = $lines[115]; }//close of if statement //print_r($lines); foreach($lindex as $value){ echo $value."<br/>"; } ?> ok..... using that script displays: Lifted Index: 1.94 C Risk: Showers probable Lifted Index @300 mb: 4.17 C Lifted Index @700 mb: 2.03 C Now.... can that script be adjusted so I can have the output be like this: Lifted Index: 1.94 Lifted Index @300 mb: 4.17 Lifted Index @700 mb: 2.03 Something maybe like a section that can give you an option to take away certain amounts of characters? If it can not be done with that script then ill leave this along tonight and beg my server admin to help me with this. Link to comment https://forums.phpfreaks.com/topic/60147-multiple-lines/#findComment-299306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.