eva21 Posted May 15, 2009 Share Posted May 15, 2009 I have the following string: $string = "Roses - Blue (Remember)"; Than I have this trim: $type = trim($string, "Roses - "); echo $type; When i echo...all i get is "lue (Remember)" When I really want is "Blue (Remember)"...why is it doing this? Link to comment https://forums.phpfreaks.com/topic/158265-php-and-trim/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2009 Share Posted May 15, 2009 Then you must have some other error in your code or the B is actually present but not visible (have you done a "view source" in your browser?), because the posted code does give: Blue (Remember) However, using trim() that way will give unexpected results because it will trim every "R", "o" "s", "e", " ", and "-" from the start and end of the string. You should probably look at using str_replace() Link to comment https://forums.phpfreaks.com/topic/158265-php-and-trim/#findComment-834704 Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 well str_replace() would replace (remove) from beginning and end just the same. And everywhere in-between. should use preg_replace instead, where you can specify beginning of string. Link to comment https://forums.phpfreaks.com/topic/158265-php-and-trim/#findComment-834710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.