w3resource
php Programming Exercies

PHP String Exercises: Remove trailing slash from a string

PHP String: Exercise-21 with Solution

Write a PHP script to remove trailing slash from a string.

Original String : 'The quick brown fox jumps over the lazy dog///'

Pictorial Presentation:

PHP String Exercises: Remove trailing slash from a string

Sample Solution:

PHP Code:

<?php
$my_str = 'The quick brown fox jumps over the lazy dog///';
echo rtrim($my_str, '/')."\n";
?>

Sample Output:

The quick brown fox jumps over the lazy dog

Flowchart :

Flowchart: Remove trailing slash from a string

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to remove part of a string.
Next: Write a PHP script to get the characters after the last '/' in an url.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming