|
Posted by Rik on 03/16/07 18:31
On Fri, 16 Mar 2007 19:15:31 +0100, Krustov <me@privacy.net> wrote:
> Swap 2007-03-15 to 15-03-2007
>
> Given i have 50,000 dates in a text file to change i'm looking for the=
> fastest way of doing it .
Fastest way, if the format is consistent:
$date_array =3D explode('-',$string);
array_reverse($date_array);
$string =3D implode('-',$date_array);
But as it is a textfile:
$oldfile =3D '/path/to/old/file';
$newfile =3D '/path/to/new/file';
$old =3D fopen($oldfile,'r');
$new =3D fopen($newfile,'w');
while($data =3D fscanf($old,"%s-%s-%s\n")){//change according to format
array_reverse($data);
fwrite($new,implode('-',$data)."\n");
}
-- =
Rik Wasmus
[Back to original message]
|