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