How to remove the first character of string in PHP?

后端 未结 13 2197
一整个雨季
一整个雨季 2020-12-02 06:00
$str=\':this is a applepie :) \';

How to use PHP, Remove the first character :

相关标签:
13条回答
  • 2020-12-02 06:19

    The code works well for me.

    $str = substr($str ,-(strlen($str)-1));
    

    Maybe, contribute with answers too.

    0 讨论(0)
  • 2020-12-02 06:21

    you can use the sbstr() function

    $amount = 1;   //where $amount the amount of string you want to delete starting  from index 0
    $str = substr($str, $amount);
    
    0 讨论(0)
  • 2020-12-02 06:23

    To remove every : from the beginning of a string, you can use ltrim:

    $str = '::f:o:';
    $str = ltrim($str, ':');
    var_dump($str); //=> 'f:o:'
    
    0 讨论(0)
  • 2020-12-02 06:24
    $str = substr($str, 1);
    

    See PHP manual example 3

    echo substr('abcdef', 1);     // bcdef
    

    Note:

    unset($str[0]) 
    

    will not work as you cannot unset part of a string:-

    Fatal error: Cannot unset string offsets
    
    0 讨论(0)
  • 2020-12-02 06:25

    Here is the code

    $str = substr($str, 1); 
    
    echo $str;
    

    Output:

    this is a applepie :)
    
    0 讨论(0)
  • 2020-12-02 06:25

    use mb_substr function

        mb_substr("我abc", 1);
    
    0 讨论(0)
提交回复
热议问题