Home  >  Article  >  Backend Development  >  字符转截取有关问题

字符转截取有关问题

WBOY
WBOYOriginal
2016-06-13 13:13:09878browse

字符转截取问题!
假设字符串$a=123/frew/4214/fsdf/123/123/dsa;$a是变量,内容会变化。
那么,怎么截取从开始到倒数第二个"/"的内容,即123/frew/4214/fsdf/123/
不要从前面开始数"/",因为不确定前面有几个‘/’,自知道不要后面数第二个‘/’后面的内容。


------解决方案--------------------
$t = explode('/', $a);
echo join('/', array_slice($t, 0, -2)) . '/';
------解决方案--------------------

PHP code
$a = '123/frew/4214/fsdf/123/123/dsa';
$t = explode('/', $a);
echo join('/', array_slice($t, 0, -2)) . '/';
<br><font color="#e78608">------解决方案--------------------</font><br>$a= explode('/',$a);<br>$s[count($s)-1]试试
<br><font color="#e78608">------解决方案--------------------</font><br>$b = join('/', array_slice($t, 0, -2)) . '/';<br><br>
<br><font color="#e78608">------解决方案--------------------</font><br>哎,6楼是开玩笑呢么?<br>$a = '123/frew/4214/fsdf/123/123/dsa';<br>$t = explode('/', $a);<br>$b=join('/', array_slice($t, 0, -2)) . '/';<br>echo $b; <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn