php - work with string Remove Trailing Slash From String PHP if(substr($string, -1) == '/') { $string = substr($string, 0, -1) } Alternative way: $string = rtrim($string, '/'); ltrim - Strip whitespace (or other characters) from the beginning of a string rtrim - Strip whitespace (or other characters) from the end of a string trim - Strip whitespace (or other characters) from the beginning and end of a string