简体   繁体   中英

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  . " /"));
                    }
                    ?>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM