Forum Moderators: coopster

Message Too Old, No Replies

Adding zero to text in php

         

andirst

10:04 am on Jun 25, 2010 (gmt 0)

10+ Year Member



Hi All,

I want to edit a text file with leading zero, for example the file is text.txt with the file content is :

:20:201006170828153
:25:186350587
:28:153
:60F:C100602IDR879511164,
:61:1006020602DR313600,NTRF//
:20:201006170828154
:25:186350587
:28:154
:60F:C100603IDR462231690,
:61:1006030603CR918000000,NTRF//
:20:201006170828155
:25:186350587
:28:155
:60F:C100604IDR703646190,
:61:1006040604DR440000000,NTRF//
:86:TARIK TRF (RTGS) | N WILLY MANOBY | HLP/121339 |0020005710DG10
:61:1006040604DR15000,NTRF//
:86:TARIK TRF (RTGS) | N WILLY MANOBY | HLP/121339 |0020005710DG10
:61:1006040604DR88500000,NTRF//

I want to insert every
:25:
with two zero, so it will look like
:25:00
and make the new file call new_text.txt

does anyone can help me with the php script?

Thanks
Andi

Alcoholico

6:01 pm on Jun 25, 2010 (gmt 0)

10+ Year Member



<?php
file_put_contents('new_text.txt', preg_replace('/\:25\:[^\n]*/', ':25:00', file_get_contents($FULL_NAME_AND_PATH_TO_THE_ORIGINAL_FILE)));
?>