Renlok Posted November 29, 2006 Share Posted November 29, 2006 what would be the code to add something into a flat file which will appear 1 line before the end but after the previous entry?if so whats the code to do this?what is mean by appearing one line before the end if you didnt understand:entry 1new entryend tagthanks for any help. Link to comment https://forums.phpfreaks.com/topic/28854-help-with-flat-file-commends/ Share on other sites More sharing options...
trq Posted November 29, 2006 Share Posted November 29, 2006 There is no function built to do this, you would need to roll your own.Load each line from the file into an array, then loop through that array adding the line to the new file, when you get to the second last line ( count($arr)-2 ) add your new line. Link to comment https://forums.phpfreaks.com/topic/28854-help-with-flat-file-commends/#findComment-132074 Share on other sites More sharing options...
Renlok Posted November 29, 2006 Author Share Posted November 29, 2006 thanks ill try that out. Link to comment https://forums.phpfreaks.com/topic/28854-help-with-flat-file-commends/#findComment-132117 Share on other sites More sharing options...
Renlok Posted November 29, 2006 Author Share Posted November 29, 2006 thanks ill try that out.i tryed[code] $fp = fopen("http://www.we-link.co.uk/sitemap.xml","a"); if(!$fp) { echo 'Error: Cannot open file.'; exit; } $arr = file("http://www.we-link.co.uk/sitemap.xml"); fwrite($fp, "<url><loc>".$url."</loc><priority>0.5</priority><changefreq>Weekly</changefreq></url>", ( count($arr)-2 )); fclose($fp);[/code]no luck any errors? Link to comment https://forums.phpfreaks.com/topic/28854-help-with-flat-file-commends/#findComment-132142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.