Re: preg_replace problem

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

 



Benjamin Adams wrote:
$file = dog.txt;
$today = date("Ymd");

function incDate($new, $date){
        //$date = settype('int');
        return $new.($date++);
}

$getOldValue = parse_ini_file($file, 1);
$newValue = $getOldValue[$today] + 1;
$oldDate = $today . " = ". $newValue;
$newDate = preg_replace('/(\d+\s\=\s)(\d+)/ie', 'incDate("$1","$2")', $oldDate);
file_put_contents($file, $newDate . "\n");

This works with one file but with multi lines I'm having trouble:
if the file has:
20060301 = 34
20060302 = 3
the file after script will be:
20060302 = 4

I want it to preserve the previous lines
so output should be:
20060301 = 34
20060302 = 4

Help would be great, thanks
Ben

The easiest way would be to get incDate to add the newline back on the end.

You could also try:

preg_replace('/(\d+\s\=\s)(\d+)/ie', 'incDate("$1","$2")' . "\n", $oldDate);

--
Postgresql & php tutorials
http://www.designmagick.com/

--
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