Home > Backend Development > PHP Tutorial > php处置字符串

php处置字符串

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 13:13:15
Original
863 people have browsed it

php处理字符串
传入参数是/Maildir/cur/usrp/或者是Maildir/cur/usrp
最后都处理成Maildir/cur/usrp
有什么方便简单方法啊 谢谢了

------解决方案--------------------
echo trim('/Maildir/cur/usrp/', '/');
------解决方案--------------------

PHP code
$newstring = trim($string, '/');
<br><font color="#e78608">------解决方案--------------------</font><br>什么意思,没太搞懂。是不是第一个字符或者最后一个字符是/,就去掉<br>用trim函数<br><br>echo trim($str,'/');去掉首尾的‘/’字符
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code

$str="/Maildir/cur/usrp/";
$str = substr($str,0,1)=="/"?substr($str,1):$str;
$str = substr($str,-1,1)=="/"?substr($str,0,-1):$str;
echo $str;

$str="/////Maildir/cur/usrp/////";
$strarr=explode("/",$str);
foreach($strarr as $k=>$s){
    if($s=="")unset($strarr[$k]);
}
echo join("/",$strarr); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template