久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php如何刪除字符串末尾字符

      我們知道字符串刪除字符的方式有好幾種,今天就來介紹三種php刪除字符串最后一個字符的函數(shù),有需要的小伙伴可以參考一下。

      php如何刪除字符串末尾字符

      方法一:substr()函數(shù)

      substr()函數(shù)返回字符串的一部分。

      語法如下:

       substr(string string, int start, int [length]);

      參數(shù)解釋:

      • 第一個參數(shù):代表原字符串;

      • 第二個參數(shù):代表從哪里開始截取;

      • 第三個參數(shù):代表我們需要截取的長度。

      實例:

      <?php $str = "1,2,3,4,5,6";  $newstr = substr($str,0,strlen($str)-1);  echo $newstr;  ?>

      結果:

      1,2,3,4,5,

      可以看到輸出結果$str最后一個字符沒有了。

      方法二:substr_replace()函數(shù)

      substr_replace()函數(shù)把字符串一部分替換成另一個字符串。

      它雖然是替換函數(shù),但是可以實現(xiàn)插入式的刪除字符。

      語法如下:

      substr_replace()(string string, int start, int [length]);

      參數(shù)解釋:

      • 第一個參數(shù):代表原字符串;

      • 第二個參數(shù):代表從哪里開始刪除;

      • 第三個參數(shù):代表需要刪除幾個字符。

      實例:

      $email='peter@qq.com'; echo substr_replace($email,'',11,1);

      輸出結果為:

      peter@qq.co

      最后一個字符m被刪除了。

      方法三:rtrim()函數(shù)

      如果字符串最后一個字符是空白字符或是特殊字符的話,可以使用rtrim()函數(shù),且我們只需要一個參數(shù)就可以,但如果最后一個字符不是空白字符或是特殊字符,我們需要指定刪除的字符。

      語法:

      string rtrim ( string $str [, string $character_mask ] )

      參數(shù)解釋:

      • 第一個參數(shù):代表原字符串;

      • 第二個參數(shù):代表需要被刪除的字符。

      示例:

      <?php     $email='peter@qq.com';     echo rtrim($email,"m"); ?>

      輸出結果為:

      peter@qq.co

      推薦學習:《PHP視頻教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號