Jump to content

[SOLVED] Find linebreaks in a string.


5kyy8lu3

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

Archived

This topic is now archived and is closed to further replies.

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