How to remove the first character of string in PHP?

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

How to use PHP, Remove the first character :

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

    The accepted answer:

    $str = ltrim($str, ':');
    

    works but will remove multiple : when there are more than one at the start.

    $str = substr($str, 1);
    

    will remove any character from the start.

    However,

    if ($str[0] === ':')
        $str = substr($str, 1);
    

    works perfectly.

    0 讨论(0)
提交回复
热议问题