untrailingslashit()
Removes the trailing slash (/) at the end of a string (URL).
The function is used to clean absolute paths or URLs.
Used By: user_trailingslashit(), trailingslashit()
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.
Returns
String. The changed string.
Usage
$url = untrailingslashit( $url );
- $string(string) (required)
- The string from which the trailing slash (/) or slashes (//) should be removed.
Examples
#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() untrailingslashit code WP 6.9.1
function untrailingslashit( $value ) {
return rtrim( $value, '/\\' );
}