How can I get the last 7 characters of a PHP string?

后端 未结 7 2135
太阳男子
太阳男子 2020-11-30 18:25

How would I go about grabbing the last 7 characters of the string below?

For example:

$dynamicstring = \"2490slkj409slk5409els\";
$newstring = some_f         


        
7条回答
  •  广开言路
    2020-11-30 18:59

    Use substr() with a negative number for the 2nd argument.

    $newstring = substr($dynamicstring, -7);
    

    From the php docs:

    string substr ( string $string , int $start [, int $length ] )

    If start is negative, the returned string will start at the start'th character from the end of string.

提交回复
热议问题