Search code examples
phpbreadcrumbs

how can i remove the first forward slash?


as you can see i show some breadcrumbs on my page. but i want to remove the first forward slash, how can i do that?

now it looks like this: / u are here: /home /page1 /page2

but it has to be like this: u are here: /home /page1 /page2

i already tried a lot but nothing seems to work.

This is my code:

                    <?php
                    $crumbs = explode("/", $_SERVER["REQUEST_URI"]);

                    foreach ($crumbs as $crumb) {
                        echo ucfirst(str_replace(foldernaam,'u are here: ', $crumb  . " /"));
                    }
                    ?>

Solution

  • use this code:

    $str = '/u are here /home /page1 /page2';
    $str = ltrim($str, '/');
    echo $str;
    

    It will return you u are here /home /page1 /page2

    You can also use this code:

    $str = '/u are here /home /page1 /page2';
    $strs = substr($str, 0);
    

    But it will remove first character while the code given above will remove the first forward slash that is suitable solution of your query.