Jump to content

multiple lines...


TFD3

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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 :o

 

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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