[!--quoteo(post=371770:date=May 6 2006, 07:11 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 6 2006, 07:11 AM) [snapback]371770[/snapback][/div][div class=\'quotemain\'][!--quotec--] You mean it's not self explanatory? :-) [code]<?php $in = file('exam.txt'); // read the whole file into an array $out = array(); // initialize the array to hold the records to be written out foreach($in as $line) { // go through the array line by line if (substr(trim($line),0,4) != 'S.L.') { // Only use those lines that don't start with "S.L." $x = explode(' ',trim($line)); // explode the trimmed line on a space to form an array with two elements. Trimming will remove the newline character $out[] = implode(' ',array_reverse($x)); // recreate a string with a space seperating the words after reversing the elements in the array } } $fp = f open('exam_out.txt','w'); f write($fp,implode("\n",$out). "\n"); // write all the lines to a file, using implode to put a newline character between each element of the array. And add a newline character to the end of the last line. f close($fp); $results = file('exam_out.txt'); // read all the lines back into another array echo '<pre>' . print_r($results,true) . '</pre>'; // and display the results. Note you could also just display the contents of the $out array. ?>[/code] Ken [/quote] ok 1 more question, why here : if (substr(trim($line),0,4) != 'S.L.') why do you use 0,4 as an argument in substr() ?