untrailingslashit()WP 2.2.0

Removes trailing forward slashes and backslashes if they exist.

The primary use of this is for paths and thus should be used for paths. It is not restricted to paths and offers no specific path support.

1 time — 0.000001 sec (speed of light) | 50000 times — 0.01 sec (speed of light) | PHP 7.3.12, WP 5.4

No Hooks.

Return

String. String without the trailing slashes.

Usage

untrailingslashit( $value );
$value (required)
-

Examples

0

#1 Demo: how it works

echo untrailingslashit( 'www/name/domen.ru/' ); //> www/name/domen.ru
echo untrailingslashit( '/' );                  //> ''
echo untrailingslashit( '../../' );             // ../..

var_dump( untrailingslashit( '' ) );       //> ''
var_dump( untrailingslashit( false ) );    //> ''
var_dump( untrailingslashit( null ) );     //> ''
var_dump( untrailingslashit( [] ) );       // NULL

Changelog

Since 2.2.0 Introduced.

untrailingslashit() code WP 6.5.4

function untrailingslashit( $value ) {
	return rtrim( $value, '/\\' );
}