Shorten a text string in PHP

前端 未结 9 2412
暗喜
暗喜 2020-12-20 02:32

Is there a way to trim a text string in PHP so it has a certain number of characters? For instance, if I had the string:

$string = \"this is a string\";

9条回答
  •  盖世英雄少女心
    2020-12-20 03:35

    function trimtext($text, $start, $len)
    {
        return substr($text, $start, $len);
    }
    

    You can call the function like this:

    $string = trimtext("this is a string", 0, 10);
    

    Would return:

    This is a

提交回复
热议问题