I have a string containing some text, the last character might (might) be a slash, which I don’t want. How do I remove that, if it exists?
Is this the “correct” way?
if(substr($str, -1) == "/") $str = rtrim($str, '/');
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
rtrimwithout a condition, it’s shorter and probably faster as well. The addedifis noise and doesn’t offer anything.