Jump to content

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);
?>

 

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.