Re: How to change the first line of a text file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/12/2010 2:10 PM, Richard Kurth wrote:

I have around 6000 text files and I need to change the first line on every one of them.

The first line is the title of the article and I need it look like this <title>the name of the article</title>

every file has the first line and the it starts the article on the second line

The files are in many directory under one main directory
like this

top directory
           fashion-school
           Dogs
           DentalAssistant
           etc..........

I need a script that will loop through each directory look at each file extract the first line and replace it with the example above. I have figured out how to pull the first line into an array but I don't no where to go from there to look in each directory and the write the data back at the top.

$f = file('GENERAL HISTORY OF DOGS.txt');
$a = '<title>' . $f[0] . '</title>';
echo $a;




Something like this should do what you want: http://pastebin.com/jKvAiGYa

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux