remove trailing slash from url php – Remove Characters At Start And End Of A String In PHP

remove trailing slash from url php – ltrim($string, ‘start’); and rtrim($string, ‘end’); Best way to remove trailing slashes in URLs with PHP

$url = rtrim($url,"/");

remove trailing slash from url php

Remove Trailing Slash From String PHP

Example

if(substr($user_line, -1) == '/') {
    $user_line = substr($user_line, 0, -1);
}

Remove Trailing Slashes From String

using the rtrim() function.

function remove_trailing_slashes( $url )
{
     return rtrim($url, '/');
}

use for the ltrim() function

function remove_leading_zeros( $number )
{
    return ltrim($number, '0');
}

remove www from url php

Read Also:  Autocomplete Search Box / textbox in PHP MySQL

This removes trailing slashes:

$str = rtrim($str, '/');

I hope you get an idea about remove trailing slash from url php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.