Jump to: navigation, search

PHP File Copy Reverse

From w3cyberlearnings

Contents

PHP Copy Reverse File

Copy from one file to another but its content is reversed order. (Last to first)

File Content (test1.txt)

A wonderful school makes a wonderful student
A wonderful person makes a wonderful heart.
A wonderful heart
A wonderful world
A wonderful person
A wonderful community

Example 1

<?php

$lines = file("test1.txt");

$fcop2 = fopen("test2.txt", 'w') or exit('unable to write to');

for ($i = count($lines) - 1; $i >= 0; $i--) {
	fwrite($fcop2, "{$lines[$i]}\n");
}
fclose($fcop2);
?>


Output(test2.txt)

A wonderful community
A wonderful person
A wonderful world
A wonderful heart
A wonderful person makes a wonderful heart.
A wonderful school makes a wonderful student

Related Links


  1. PHP File Linux vs. Windows
  2. PHP File Information
  3. PHP File Create
  4. PHP File Close
  5. PHP File Read
  6. PHP File Read Reverse
  1. PHP File Write
  2. PHP File Write to end or append to
  3. PHP File Write at Beginning
  4. PHP File Write at specific location
  5. PHP File Truncate
  6. PHP File Replace a specific word
  1. PHP File Replace a specific word with associative array
  2. PHP File Copy File
  3. PHP File Copy Reverse
  4. PHP File Search within file
  5. PHP File Delete File
  6. PHP File Template
  1. PHP File Email Template
  2. PHP File Template with MySQL
  3. PHP File Access with MySQL
Navigation
Web
SQL
MISC
References