如何刪除 PHP 字串的第一個字元?


刪除 PHP 字串第一個字元,程式碼如下−

示例

 現場演示

<?php
   $str = "Test";
   echo "Before removing the first character = ".$str;
   $res = substr($str, 1);
   echo "
After removing the first character = ".$res; ?>

輸出

將生成以下輸出 −

Before removing the first character = Test
After removing the first character = est

示例

我們現在來看另一個示例

 現場演示

<?php
   $str = "Demo";
   echo "Before removing the first character = ".$str;
   $res = ltrim($str, 'D');
   echo "
After removing the first character = ".$res; ?>

輸出

將生成以下輸出−

Before removing the first character = Demo 
After removing the first character = emo

更新於: 2019-12-27

2K+ 瀏覽

開始你的職業

透過完成課程獲得認證

開始使用
廣告
© . All rights reserved.