Jump to content

Recommended Posts

Hi!  I was working on writing some scripts to pull weather data from noaa.gov's weather text files and I'm trying to think of a good way to go about it.  One thing that would really help is if I could find a way to detect where lines breaks are in the string.  Is it possible to use strpos(); to find line breaks?  If I can, then I could throw each line of data into it's own variable (or array).

 

Here's the text file I'll be reading from if it helps any: ftp://tgftp.nws.noaa.gov/data/observations/metar/decoded/KOJC.TXT

 

I don't have to do this but it would make things easier for me.  Thanks ahead of time.

Link to comment
https://forums.phpfreaks.com/topic/141394-solved-find-linebreaks-in-a-string/
Share on other sites

file — Reads entire file into an array

 

example

<?php
$lines = file('ftp://tgftp.nws.noaa.gov/data/observations/metar/decoded/KOJC.TXT');

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
?>

file — Reads entire file into an array

 

example

<?php
$lines = file('ftp://tgftp.nws.noaa.gov/data/observations/metar/decoded/KOJC.TXT');

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
?>

 

this is excellent, i appreciate the help ;D

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.