Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. $filepathname = "./test.txt";
  2. $target = "A line after which the code should be added";
  3. $newline = "A new line";
  4.  
  5. $stats = file($filepathname, FILE_IGNORE_NEW_LINES);
  6. $offset = array_search($target,$stats) +1;
  7. array_splice($stats, $offset, 0, $newline);
  8. file_put_contents($filepathname, join("n", $stats));
  9.  
  10. $dir = dirname(__FILE__);
  11. glob_recursive($dir);
  12. function glob_recursive($dir){
  13. foreach(glob($dir."*", GLOB_NOSORT) as $filename){
  14. if(is_dir($filename)) glob_recursive($filename."/*");
  15. else{
  16. foreach(glob($dir."test.txt", GLOB_NOSORT) as $filename){
  17. echo $filename."<br>";
  18. }
  19. }
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement