PHP Help

Associate
Joined
18 Oct 2002
Posts
100
Text to convert in file result.txt...
<Date>Oct 31 2006 12:00AM</Date>

File...
<?php
$filename = "result.txt";
$data = preg_replace('/<Date>(.*)<\/Date>/Uie', "'<Date>'. date(\"dmY\",strtotime('$i')) .'</Date>'", file_get_contents($filename));
$fp = fopen($filename, "w");
fwrite($fp, $data);
fclose($fp);
?>

Needs to be converted to dmY
Can't get it to work :(

Plz can anyone point me in the right direction

Thanks in advance
 
Backreferences are numeric according to the 'n'th parenthesized pattern' i.e. the first backreference is $1, the second $2 and so on.

So, change your $i to $1, and it should fix the issue:
Code:
<?php
$filename = "result.txt";
$data = preg_replace('/<Date>(.*)<\/Date>/Uie', 
        "'<Date>'. date(\"dmY\",strtotime('[COLOR=Yellow]$1[/COLOR]')) .'</Date>'",
        file_get_contents($filename));
$fp = fopen($filename, "w");
fwrite($fp, $data);
fclose($fp);
?>
 
Back
Top Bottom