Remove first 4 characters of a string with PHP

前端 未结 7 1236
我在风中等你
我在风中等你 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
    
    0 讨论(0)
  • 2020-12-02 05:07
    $num = "+918883967576";
    
    $str = substr($num, 3);
    
    echo $str;
    

    Output:8883967576

    0 讨论(0)
  • 2020-12-02 05:07

    use php's built in substr function...

    $result = substr("This World", 4); 
    
    //will return " World"
    
    0 讨论(0)
  • 2020-12-02 05:14

    If you’re using a multi-byte character encoding and do not just want to remove the first four bytes like substr does, use the multi-byte counterpart mb_substr. This does of course will also work with single-byte strings.

    0 讨论(0)
  • 2020-12-02 05:17

    You could use the substr function please check following example,

    $string1 = "tarunmodi";
    $first4 = substr($string1, 4);
    echo $first4;
    
    Output: nmodi
    
    0 讨论(0)
  • 2020-12-02 05:18

    You could use the substr function to return a substring starting from the 5th character:

    $str = "The quick brown fox jumps over the lazy dog."
    $str2 = substr($str, 4); // "quick brown fox jumps over the lazy dog."
    
    0 讨论(0)
提交回复
热议问题