drath Posted January 6, 2009 Share Posted January 6, 2009 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 https://forums.phpfreaks.com/topic/139760-trimming-based-on-string-not-characters/ Share on other sites More sharing options...
DarkWater Posted January 6, 2009 Share Posted January 6, 2009 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 https://forums.phpfreaks.com/topic/139760-trimming-based-on-string-not-characters/#findComment-731208 Share on other sites More sharing options...
drath Posted January 6, 2009 Author Share Posted January 6, 2009 Oh sorry, yes it would do that . 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 https://forums.phpfreaks.com/topic/139760-trimming-based-on-string-not-characters/#findComment-731211 Share on other sites More sharing options...
DarkWater Posted January 6, 2009 Share Posted January 6, 2009 Err, okay...trim() wouldn't accomplish that ANYWAY. You're looking for str_replace(). $str = str_replace('ABC', '', $str); Link to comment https://forums.phpfreaks.com/topic/139760-trimming-based-on-string-not-characters/#findComment-731213 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.