Jump to content

Trimming Based on String, Not Characters


drath

Recommended Posts

I have searched around for this and haven't really found anything except for the substr() function which doesn't work in this situation. Basically I want to use the trim() function to trim out a string of "ABC", yet when I use a function like this:

 

trim($file, "ABC");

 

on for example:

 

"A TEST B TEST C"

 

It will result in " TEST TEST " because it is stripping the characters rather than a full string. Does anybody know a way to do this? Thanks!

 

Link to comment
Share on other sites

Well, actually, it results in "TEST B TEST".  trim() actually just makes a character mask of the characters in the 2nd parameter and uses that to pull the left and right characters off and stuff.  What are you trying to do?  Remove a specific string from the end of a line?

Link to comment
Share on other sites

Oh sorry, yes it would do that :P. Here is an example of the intended function using "ABC":

 

ABC_FILE
FILEABC
FI_ABC_LE

 

Would all turn into the following:

 

_FILE
FILE
FI__LE

 

Thanks again for replying/helping DarkWater.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.