如何删除 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+ 浏览

开始你的职业

通过完成课程获得认证

开始使用
广告