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!
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
ASKER
I figured it out.