freelance84 Posted May 24, 2010 Share Posted May 24, 2010 Users are able to add single line comments to a page. If the last character is a full stop I want to be able to remove it. After researching the substr I thought this would work: if(substr($get_comment_to_add, -1) == ".") { substr_replace($get_comment_to_add ,"",-1); } I know the "substr" bit in the "if" returns the last character. So I am assuming the =="." is incorrect. I have tried escaping with a backslash but it still didn't work. Any ideas anyone? Also I cannot use str_replace because it is only the last period i want to remove, not any others in between. Quote Link to comment Share on other sites More sharing options...
Bladescope Posted May 24, 2010 Share Posted May 24, 2010 rtrim($get_comment_to_add, '.'); No need for the if check. Furthermore, this will remove multiple full stops too. Quote Link to comment Share on other sites More sharing options...
freelance84 Posted May 25, 2010 Author Share Posted May 25, 2010 Hi, yea i got it to work with the folloing: if(substr($get_comment_to_add, -1) == ".") { $com_prt1 = substr_replace($get_comment_to_add ,"",-1); } else{ $com_prt1 = $get_comment_to_add; } This takes out the last character if it's a period and leaves in any others in between Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.