Remove first 4 characters of a string with PHP

前端 未结 7 1247
我在风中等你
我在风中等你 2020-12-02 04:43

How can I remove the first 4 characters of a string using PHP?

7条回答
  •  情歌与酒
    2020-12-02 05:05

    function String2Stars($string='',$first=0,$last=0,$rep='*'){
      $begin  = substr($string,0,$first);
      $middle = str_repeat($rep,strlen(substr($string,$first,$last)));
      $end    = substr($string,$last);
      $stars  = $begin.$middle.$end;
      return $stars;
    }
    

    example

    $string = 'abcdefghijklmnopqrstuvwxyz';
    echo String2Stars($string,5,-5);   // abcde****************vwxyz
    

提交回复
热议问题