View Full Version : Strange result using eregi_replace - help!

02-24-2008, 02:34 PM
Hi there.

I have a database with some figures in it and they are formatted as decimals with one figure after decimal place.

If the figure finishes in .0 I want to remove the .0
If the figure ends in .1 (to .9) then I want to keep it

I used the following:

echo eregi_replace('.0', '', $row['figure']).' cms';

Strange thing that happens is that when the figure in the database is 20.0 I get no figure displayed! I just get "cms". If I change the figure to 21.0 in the database, it displays it perfectly!

I cannot see why this would be!

Any help trulty appreciated!

02-24-2008, 02:42 PM
It's OK - I have solved it!

I forgot to put the backslash before the period:

echo eregi_replace('\.0', '', $row['figure']).' cms';

That has done the trick!

I was looking at it for ages! Time for a break I think!