DARTHTAMPON
02-19-2007, 07:55 PM
$fp = fopen('car.txt','r');
$fp1 = fopen('cars1.txt','w');
while (!feof($fp))
{
$line = fgets($fp); //use 2048 if very long lines
# 1988 Acura Legend Coupe L 9 . 6 17 . 2
$re1 = '^([0-9]{4} \s [a-zA-Z]+ \s [a-zA-Z]+ \s) \.+ ([0-9]{1,2}\.[0-9]{1,2} \s[0-9]{1,2}\.[0-9]{1,2})$';
$re2 = '^([0-9]{4} , [a-zA-Z]+ , [a-zA-Z]+ ,) \.+ ([0-9]{1,2}\.[0-9]{1,2}, [0-9]{1,2}\.[0-9]{1,2})$';
# 1988,Acura, Legend, Coupe L, 9.6, 17.2
fwrite($fp1, ereg_replace ($re1, $re2, $line)."\n");
}
fclose($fp);
fclose($fp1);
?>
the string comes in as $re and needs to be changed to $re1 (basicly the noted \s need to become ','. When I run this I get an exact printout of the original record. Why is it not doing anything? The regexp seems to be allright when validated.
any ideas?
$fp1 = fopen('cars1.txt','w');
while (!feof($fp))
{
$line = fgets($fp); //use 2048 if very long lines
# 1988 Acura Legend Coupe L 9 . 6 17 . 2
$re1 = '^([0-9]{4} \s [a-zA-Z]+ \s [a-zA-Z]+ \s) \.+ ([0-9]{1,2}\.[0-9]{1,2} \s[0-9]{1,2}\.[0-9]{1,2})$';
$re2 = '^([0-9]{4} , [a-zA-Z]+ , [a-zA-Z]+ ,) \.+ ([0-9]{1,2}\.[0-9]{1,2}, [0-9]{1,2}\.[0-9]{1,2})$';
# 1988,Acura, Legend, Coupe L, 9.6, 17.2
fwrite($fp1, ereg_replace ($re1, $re2, $line)."\n");
}
fclose($fp);
fclose($fp1);
?>
the string comes in as $re and needs to be changed to $re1 (basicly the noted \s need to become ','. When I run this I get an exact printout of the original record. Why is it not doing anything? The regexp seems to be allright when validated.
any ideas?