简体   繁体   English

如何删除第一个正斜杠?

[英]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现在看起来像这样:/你在这里:/home /page1 /page2

but it has to be like this: u are here: /home /page1 /page2但它必须是这样的:你在这里:/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它会返回你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.但它会删除第一个字符,而上面给出的代码将删除第一个适合您的查询解决方案的正斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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