Link to home
Create AccountLog in
Avatar of gesmuk
gesmuk

asked on

Remove characters from the end of a string

Hi guys,

I'm looking for a method of removing a few characters from the end of a string in PHP. I saw a few, because it could be 1, 2 or 3 of them!

Basically, a string is being passed that could look like any of these.

dummy.exe.1
dummy.exe.12
dummy.exe.123

And I want to strip this so that I always end up with 'dummy.exe'.

I've thought about using rtrim, but I can't figure out the logic of removing everything from (and including) the last '.' onwards, regardless of how many characters there are.

Any help would be appreciated!
SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of gesmuk
gesmuk

ASKER

I've requested that this question be deleted for the following reason:

I figured it out.
Instead of deleting your question, please post the solution you used.  If it's based on the responses of the Experts here, it is appropriate to award points.  If you've come up with a completely novel way of trimming string data, we would certainly want to learn about it.  Thanks, ~Ray