Jump to content

Need help writting code


ETennDude

Recommended Posts

I am trying to write a php file that will copy these 4 files

 

http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.01.txt

http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.02.txt

http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.03.txt

http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.04.txt

 

Then combin them into one file

 

Then save it as us-scs.html

 

I have written all the other code for displaying and editing, and etc. BUT this one has me stumped.. :-)

 

ANY help would be great.

 

Thanks in advance.

Perry

Link to comment
https://forums.phpfreaks.com/topic/150067-need-help-writting-code/
Share on other sites

ok, this should be quite an easy one.

 

First, to grab the contents of those files look into using file_get_contents();

 

Once you have 4 seperate strings with their contents you can add them all together like this.

 

$alltextfilesinone=$text1.$text2.$text3.$text4;

 

And then to write it all to a new file on your hosting you should look into fwrite();

something like this...

 

<?php 
$arrFiles = array(
					"http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.01.txt",
					"http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.02.txt",
					"http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.03.txt",
					"http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.04.txt"
					);
$strHTML = "";
for($i=0;$i<count($arrFiles)$i++) {
$arrTemp = file($arrFiles[$i]);
$strHTML .= implode("", $arrTemp);
}

$fd = fopen("/path/to/us-scs.html", "w");
fwrite($fd, $strHTML);
fclose($fd);
?>

A different version of samshel's:

 

$arrFiles = array(
                  "http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.01.txt",
                  "http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.02.txt",
                  "http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.03.txt",
                  "http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.04.txt"
                  );
			  
foreach($arrFiles as $file)
$t .= file_get_contents($file);

$theFile= fopen("log/comment.php", "w");
fwrite($theFile, $t);
fclose($theFile);
?>

I wudda opted for something slightly different.

<?php 
$arrFiles = array(
                  "http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.01.txt",
                  "http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.02.txt",
                  "http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.03.txt",
                  "http://weather.noaa.gov/pub/data/raw/fp/fpus20.kwbn.scs.04.txt"
                  );
$content='';
foreach($arrFiles as $file)
    $content .= file_get_contents($file);
file_put_contents ('/path/to/us-scs.html',$content);
?>

 

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.