rss - Prepending this PHP File -


i'm little stuck attempting prepend document php. please see below code itself.

<?php  if(isset($_post['inputtitle']) && isset($_post['inputdate']) && isset($_post['inputlink'])) {       $data = "<item>" . "\r\n" . "<title>" . $_post['inputtitle'] . "</title>" . "\r\n" . "<description>" . $_post['inputdate'] . "</description>" . "\r\n" . "<link>" . $_post['inputlink'] . "</link>" . "\r\n" . "</item>" . "\r\n" . "\r\n";     $ret = file_put_contents('filename.rss', $data, file_append | lock_ex);     if($ret === false) {         die('there error writing file');     }     else {         echo "<b>thank adding news item.</b> <br />";         echo "if news item not appear on application, please contact support including screenshot of webpage. <br />";         echo "<br />";         echo "<br />";         echo "###################### <br />";         echo "$ret bytes written file. <br />";         echo "###################### <br />";      } } else {    die('no post data process'); }    ?>  

this code works writing bottom of file, i'd add top of it.

i'm creating rss feed manually, , ios application sorts them top bottom reads them.

if understood correctly , if want add content top of file, you'd need contents of first;

$content = file_get_contents("filename.rss"); 

once have contents can create new content this;

$data = "<item>" . "\r\n" . "<title>" . $_post['inputtitle'] . "</title>" . "\r\n" . "<description>" . $_post['inputdate'] . "</description>" . "\r\n" . "<link>" . $_post['inputlink'] . "</link>" . "\r\n" . "</item>" . "\r\n" . "\r\n";  $content = $data.$content; 

later save file;

$ret = file_put_contents("filename.rss", $data, lock_ex); 

shortly replace line;

$ret = file_put_contents('filename.rss', $data, file_append | lock_ex); 

with this;

$content = file_get_contents("filename.rss"); $ret = file_put_contents("filename.rss", $data.$content, lock_ex); 

Comments