...

View Full Version : PHP - file_put_contents - put new line above content



5ulo
03-09-2010, 09:47 PM
Hello, i am new here :) and i have - maybe simple - question. How to put new line to txt file (file_put_contents - FILE_APPEND) above the text. My script puts new line under the contents and that's not good for me.
Thank you

mlseim
03-09-2010, 10:03 PM
Show us your script.

5ulo
03-09-2010, 10:10 PM
<?php
include('class-search.php');
$html = file_get_html('http://deluxetelevision.com/deluxe-radio/');
$polozka = $html->find('span.playlist_stunde_time');
foreach($polozka as $playlist)
echo $playlist->plaintext . '<br />';

$file = 'playlist.txt';
foreach($polozka as $playlist)
{
file_put_contents($file, $playlist->plaintext ."\n", FILE_APPEND);
}
?>

_Aerospace_Eng_
03-09-2010, 10:50 PM
The simplest way would be to do a file_put_contents outside of the foreach however you may need to truncate the file first and then use the foreach to append the contents.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum