views:

508

answers:

2

How to remove the last character only if it's a period?

$string = "something here.";
$output = 'something here';
+11  A: 
$output = rtrim($string, '.');
Alix Axel
@Alix: yes forgot about `rtrim` a lot more easier ... !
RageZ
What I was going to suggest.
Martin Bean
+3  A: 

using rtrim replaces all "." at the end, not just the last character

$string = "something here..";
echo preg_replace("/\.$/","",$string);
ghostdog74
I'm guessing the OP wants to remove all '.' at the end, otherwise why remove just one? ;)
Tor Valamo
yes, i am guessing that too. just following the question as close as possible.
ghostdog74