Split string into 2 pieces by length using PHP

前端 未结 3 1834
别跟我提以往
别跟我提以往 2021-01-17 08:00

I have a very long string that I want to split into 2 pieces.

I ws hoping somebody could help me split the string into 2 separate strings.

I need the first s

3条回答
  •  半阙折子戏
    2021-01-17 08:20

    This is another approach if you want to break a string into n number of equal parts

     0 && $string_length < 21):
        $parts = ceil($string_length / 2); // Break string into 2 parts
        $str_chunks = chunk_split($string, $parts);
        break;
    
      default:
        $parts = ceil($string_length / 3); // Break string into 3 parts
        $str_chunks = chunk_split($string, $parts);
        break;
    
    }
    
    $string_array = array_filter(explode(PHP_EOL, $str_chunks));
    
    ?>
    

提交回复
热议问题