php preg_replace , I need to replace everything after a dot (e.g 340.38888 > need to get clean 340) -


I need to change everything after the dot. I know that it can be done with regex, but I I'm still a newbie and I do not understand the correct syntax, so please help me with this.

I tried the bellow code but did not work: / P>

 $ x = "340.888888"; $ Pattern = "/*./" $ y = preg_replace ($ patterns, "", $ x); Print_r ($ x); 

Thanks, Michael

I may be wrong, but to use it Sounds like RegEx Hummer for a specially non-nail size problem. If you're just trying to minimize a positive floating point number, you

  $ x = 340.888888; $ Y = Floor ($ x); Edit: As stated by Techpriester's remarks, it always spins down (so -4.5 in -3.5). If it is not what you want, then you can only use one cast, as  $ y = (int) $ x . 


Comments