ballhogjoni Posted January 21, 2009 Share Posted January 21, 2009 Any ideas? I thought str_replace would work but it doesn't. Link to comment https://forums.phpfreaks.com/topic/141832-solved-how-to-strip-the-last-s-from-the-word-shows/ Share on other sites More sharing options...
cytech Posted January 21, 2009 Share Posted January 21, 2009 Hello, I think this might be able to help you: http://us.php.net/manual/en/function.strrchr.php Link to comment https://forums.phpfreaks.com/topic/141832-solved-how-to-strip-the-last-s-from-the-word-shows/#findComment-742597 Share on other sites More sharing options...
ballhogjoni Posted January 21, 2009 Author Share Posted January 21, 2009 No that doesn't do what I need. Link to comment https://forums.phpfreaks.com/topic/141832-solved-how-to-strip-the-last-s-from-the-word-shows/#findComment-742607 Share on other sites More sharing options...
cytech Posted January 21, 2009 Share Posted January 21, 2009 Give this a go then: http://us.php.net/manual/en/function.strrpos.php Once you know the position of the element you can substr it. Link to comment https://forums.phpfreaks.com/topic/141832-solved-how-to-strip-the-last-s-from-the-word-shows/#findComment-742615 Share on other sites More sharing options...
bungee Posted January 21, 2009 Share Posted January 21, 2009 How about the function http://us.php.net/manual/en/function.substr.php It is what I used to do the same thing. I am new to php but from what I gather, you tell it where to start and how much to keep. If the length changes often then you could just use the size of the variable to tell it to keep all but the last letter. I have no clue as to how efficient it is though. I should have read it first. $rest = substr("abcdef", 0, -1); // returns "abcde" Link to comment https://forums.phpfreaks.com/topic/141832-solved-how-to-strip-the-last-s-from-the-word-shows/#findComment-742623 Share on other sites More sharing options...
ballhogjoni Posted January 21, 2009 Author Share Posted January 21, 2009 this is what I was looking for, so it worked after all. substr(Shows, 0, (strlen(Shows)-1)); Link to comment https://forums.phpfreaks.com/topic/141832-solved-how-to-strip-the-last-s-from-the-word-shows/#findComment-742630 Share on other sites More sharing options...
DarkWater Posted January 21, 2009 Share Posted January 21, 2009 <?php $string = "Shows"; $string = rtrim($string, 's'); echo $string; ?> If you want a more comprehensive solution that will strip ANY word of a trailing 's': <?php $string = "Here, we have some words with letters on the end. Enjoy the shows!"; $string = preg_replace('/([a-z]+?)s(?=\s|(\b.)?$)/i', '$1', $string); echo $string; Link to comment https://forums.phpfreaks.com/topic/141832-solved-how-to-strip-the-last-s-from-the-word-shows/#findComment-742635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.