How to remove the first character of string in PHP?

后端 未结 13 2306
一整个雨季
一整个雨季 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.

提交回复
热议问题