I need to replace everything after a dot . I know that it can be done with regex but I’m still novice and I don’t understand the proper syntax so please help me with this .
I tried the bellow code but doesn’t work :
$x = "340.888888"; $pattern = "/*./" $y = preg_replace($pattern, "", $x); print_r($x);
thanks ,
Michael
I may be wrong, but this sounds like using the RegEx hammer for an eminently non-nail shaped problem. If you’re just trying to truncate a positive floating point number, you can use
Edit: As pointed out by Techpriester’s comment, this will always round down (so -3.5 becomes -4). If that’s not what you want, you can just use a cast, as in
$y = (int)$x.