My current code
[code=php]
$fp = fopen(‘./car.txt’,’r’);
$fp1 = fopen(‘./cars1.txt’,’w’);
while (!feof($fp) )
{
$line = fgets($fp);
# 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})$’;
echo ereg_replace ($re1, $re2, $line);
fwrite($fp1, ereg_replace ($re1, $re2, $line).”n”);
}
fclose($fp);
fclose($fp1);
What I have
[code]
1997 Acura 2.2CL 8.9 16.7
2002 Acura 3.2CL Type S 6.8 15.0
1996 Acura 3.2TL 8.1 16.4
1999 Acura 3.2TL 7.4 15.7
2002 Acura 3.2TL Type S 6.2 14.8
2003 Acura 3.2CL Type-S 6.5 14.9
1986 Acura Integra RS 9.3 17.0
1986 Acura Integra LS 8.8 16.5
1989 Acura Integra LS 9.3 17.1
1990 Acura Integra 3-Dr GS 9.2 16.8
What I need
[code]
1997, Acura, 2.2CL, 8.9, 16.7
2002, Acura, 3.2CL Type S, 6.8, 15.0
1996, Acura, 3.2TL, 8.1, 16.4
1999, Acura, 3.2TL, 7.4, 15.7
2002, Acura, 3.2TL Type S, 6.2, 14.8
2003, Acura, 3.2CL Type-S, 6.5, 14.9
1986, Acura, Integra RS, 9.3, 17.0
1986, Acura, Integra LS, 8.8, 16.5
1989, Acura, Integra LS, 9.3, 17.1
1990, Acura, Integra 3-Dr GS, 9.2, 16.8
Question is how can you do it?
ereg doesnt seem to work for me so I must have a bug somewhere in there.
erag takes the 3rd argument testing against the 1st argument. that is then passed to be replaced by the 2nd
are commas key words in regexp? If not why isnt this working? I am very confident in the re’s.