Hello,
This network has helped me greatly on many occassions in the past, this is my first post here as I cannot find the answer elsewhere =/
I am trying to display only the second line (the actual METAR report, not the date) from this text file: ftp://tgftp.nws.noaa.gov/data/observ...tions/KMEM.TXT
Another problem with this is that my host does not allow URL file access for security reasons I presume. If anyone can help, or just stear me in the right direction I'd appreciate it!
Thanks so much!
6 2076
flydev -
well i'm really a .net developer and do not have a lot of experiance with php, but if I understand your question correctly, then I understand the logic of what you are trying to accomplish.
first you need to get the data into your application. in .net i would use a web request object to make my request for the file (using the ftp url you provided)... I searched around for a webrequest object for php and could not successfully find what i was looking for.. the closest I found was from the Mojave 3.0.0 api in which has a class registered under requests called WebRequest. the problem there is that I cant find any way to download that file (and related files) - from http://mojave.org.
so when you get your data which will be essentially a string, split it into an array by the carrige return [line feed] and by the look of the text file should be the second index of that array.. now simply plug that into wherever you want.
here is an example of how i would do it in .net
protected void Page_Load(object sender, EventArgs e)
{
FtpWebRequest rq = (FtpWebRequest)WebRequest.Create("ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KMEM.TXT");
rq.Method = WebRequestMethods.Ftp.DownloadFile;
WebResponse rsp = rq.GetResponse();
Stream str = rsp.GetResponseStream();
StreamReader sr = new StreamReader(str, System.Text.Encoding.ASCII);
Response.Write(sr.ReadToEnd());
}
I'll keep looking for a way to perform a webrequest and post here if i find one.
good luck,
odobo
Hello,
This network has helped me greatly on many occassions in the past, this is my first post here as I cannot find the answer elsewhere =/
I am trying to display only the second line (the actual METAR report, not the date) from this text file: ftp://tgftp.nws.noaa.gov/data/observ...tions/KMEM.TXT
Another problem with this is that my host does not allow URL file access for security reasons I presume. If anyone can help, or just stear me in the right direction I'd appreciate it!
Thanks so much!
ok - maybe that was a little too much for php-- it's actually a lot easier than this.. just do this...
[PHP]$filename = "ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KMEM.TXT";
$lineNumber = 1;
if (!($filearray = file ($filename))) {
print "Can't open file $filename";
}
else {
while (list ($line_number, $line_contents) = each ($filearray)) {
// do something with $line_contents...
if($lineNumber==2)
echo $line_contents."<br />";
$lineNumber++;
}
}[/PHP]
-odobo
flydev -
well i'm really a .net developer and do not have a lot of experiance with php, but if I understand your question correctly, then I understand the logic of what you are trying to accomplish.
first you need to get the data into your application. in .net i would use a web request object to make my request for the file (using the ftp url you provided)... I searched around for a webrequest object for php and could not successfully find what i was looking for.. the closest I found was from the Mojave 3.0.0 api in which has a class registered under requests called WebRequest. the problem there is that I cant find any way to download that file (and related files) - from http://mojave.org.
so when you get your data which will be essentially a string, split it into an array by the carrige return [line feed] and by the look of the text file should be the second index of that array.. now simply plug that into wherever you want.
here is an example of how i would do it in .net
protected void Page_Load(object sender, EventArgs e)
{
FtpWebRequest rq = (FtpWebRequest)WebRequest.Create("ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KMEM.TXT");
rq.Method = WebRequestMethods.Ftp.DownloadFile;
WebResponse rsp = rq.GetResponse();
Stream str = rsp.GetResponseStream();
StreamReader sr = new StreamReader(str, System.Text.Encoding.ASCII);
Response.Write(sr.ReadToEnd());
}
I'll keep looking for a way to perform a webrequest and post here if i find one.
good luck,
odobo
odobo, thanks so much for your help! Looking at what you provide, it looks like exactly what I need, and I am sure it would work perfectly, however the method used to retrieve the file is not permitted on my current host, and is not on most hosts I've learned =(
I've learned that NOAA offers similar data via an XML feed, but the same dillema exists of URL access denial from my host. In other words, URL's are not permitted as sources.
Thanks again!
ok - maybe that was a little too much for php-- it's actually a lot easier than this.. just do this...
[PHP]$filename = "ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KMEM.TXT";
$lineNumber = 1;
if (!($filearray = file ($filename))) {
print "Can't open file $filename";
}
else {
while (list ($line_number, $line_contents) = each ($filearray)) {
// do something with $line_contents...
if($lineNumber==2)
echo $line_contents."<br />";
$lineNumber++;
}
}[/PHP]
-odobo
Hmm, I've dug a little deeper and it appears the default retrieval method uses fopen, and by using CURL, it actually works.
Furthermore, I am not sure if it does this for all files retrieved, but when printing the entire file, it combines it to one line. Perhaps it doesnt recognize line breaks in .txt files? I will continue to work on modifying the script you provided and post the results if i come up with em =)
Thanks!
ok, got it!
Turns out it does NOT recognize line breaks after all. The following worked like a champ:
[PHP]<? $ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KMEM.TXT');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$metar = substr($file_contents, 21); // 21 is the number of characters after 0 to begin parsing
echo $metar;
?>[/PHP]
Even though I didn't end up having to use your script, it sparked a chain of thoughts, im sure you know how that goes ;-) I'll keep your method for future reference. Much appreciated!
ok, got it!
Turns out it does NOT recognize line breaks after all. The following worked like a champ:
[PHP]<? $ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/KMEM.TXT');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$metar = substr($file_contents, 21); // 21 is the number of characters after 0 to begin parsing
echo $metar;
?>[/PHP]
Even though I didn't end up having to use your script, it sparked a chain of thoughts, im sure you know how that goes ;-) I'll keep your method for future reference. Much appreciated!
I believe line breaks, in .txt files, are known as '\n' - newline characters.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Google Mike |
last post by:
On Linux, I need to ask what your favorite installation options are for
a PHP app as a kind of poll. In Part 1, I discussed the Install Wizard
preference that you might have. In Part 2, here, I'm...
|
by: Julie |
last post by:
I have an html file where I display name,address,zip. It is one per line so
it is basicall a list of addresses.
But I would like ie6 to force the download prompt of this long list of names...
|
by: haylow |
last post by:
Hi
I am new to ASP.NET and am working on an application that runs on a
webserver. The user will open up the web interface in a browser on
their local machine and enter a path to a directory. I...
|
by: RAJ |
last post by:
In our multi-tier application, we have several ASP.NET user controls which
will update the same data source provided by middle tier logic.
In this particular scenario we have one user control...
|
by: Tim Reynolds |
last post by:
Team,
I am developing a web service. In testing in on my enw PC, I am expecting to
see exceptions thrown appear on my browser. Instead I am getting an HTTP 500
Internal Server Error page and I am...
|
by: Christopher Brandsdal |
last post by:
Hi!
I have problems displaying a XML-file the way i want on my website.
This is the link to the file I have to display(ps: the file is on a remote
server, so I have to the file via http or...
|
by: David W. Fenton |
last post by:
I've been struggling the last two days with something I thought was
very easy, which is to open a web page with a form on it and
populate the form with data passed in a query string (either POST or...
|
by: ted |
last post by:
I have an old link that was widely distributed. I would now like to
put a link on that old
page that will go to a new page without displaying anything.
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |