ETennDude Posted March 18, 2009 Share Posted March 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/150067-need-help-writting-code/ Share on other sites More sharing options...
sloth456 Posted March 18, 2009 Share Posted March 18, 2009 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(); Quote Link to comment https://forums.phpfreaks.com/topic/150067-need-help-writting-code/#findComment-788133 Share on other sites More sharing options...
samshel Posted March 18, 2009 Share Posted March 18, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/150067-need-help-writting-code/#findComment-788134 Share on other sites More sharing options...
Maq Posted March 19, 2009 Share Posted March 19, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/150067-need-help-writting-code/#findComment-788139 Share on other sites More sharing options...
laffin Posted March 19, 2009 Share Posted March 19, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/150067-need-help-writting-code/#findComment-788141 Share on other sites More sharing options...
Maq Posted March 19, 2009 Share Posted March 19, 2009 I wudda opted for something slightly different. It would make sense If I used file_get_contents to use file_put_contents... lol Quote Link to comment https://forums.phpfreaks.com/topic/150067-need-help-writting-code/#findComment-788435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.