The Str_split () function of the PHP string is used

Source: Internet
Author: User
Tags spl

Str_split
  • (PHP 5, PHP 7)
  • Str_split-convert a string to an array
  • str_split-converting a string to an array
Description
arraystr_split($string[,$split_length1])//Converts a string to an array.//将一个字符串转换为数组。
Parametersstring
    • The input string.
    • The input string.
Split_length
    • Maximum length of the chunk.
    • The length of each paragraph.
Return Values
    • If The optional split_length parameter is specified, the returned array would be broken down to chunks with each being SP Lit_length in length, otherwise chunk would be a character in length.
    • If an optional split_length parameter is specified, each element in the returned array is a block of characters with a length of split_length, otherwise each word converts sequential blocks to a single character.
    • FALSE is returned if split_length are less than 1. If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array Eleme Nt.
    • Returns FALSE if Split_length is less than 1. If the split_length parameter exceeds the length of string strings, the entire string is returned as an array of only one element.
Examples
<?php/*** Created by Phpstorm.* User:zhangrongxiang* DATE:2018/3/7* Time: PM 10:24 */$str="Hello World";//[0] = h; [1] = = e; [2] = = l; [3] = = l; [4] = = O; [5] = =; [6] = W; [7] = = O; [8] = R; [9] = = l; [Ten] = dPrint_r( Str_split( $str ) );/** [0] = he* [1] ~ = LL* [2] = = O* [3] = wo* [4] = = RL* [5] + = d */Print_r( Str_split( $str, 2 ) );/** [0] = = Hello* [1] = Worl* [2] + = d */Print_r( Str_split( $str, 5 ) );//php Warning:str_split (): The length of each segment must being greater than zero in file on line//print_r (Str_split ($str, -5));////////////////////////////////////////////////////////////////////////functionStr_split_unicode( $str, $l=0 ){if ( $l>0 ){$ret=Array();        $len=Mb_strlen( $str, "UTF-8" );         for ( $i=0; $i<$len; $i+=$l ){$ret[]=Mb_substr( $str, $i, $l, "UTF-8" );}return $ret;}return Preg_split( "//u", $str,-1, Preg_split_no_empty );}//[0] = one//[1] = Cut//[2] = All//[3] =//[4] = + piecesPrint_r(Str_split_unicode( "All Documents" ) );//[0] = everything//[1] = FilePrint_r(Str_split_unicode( "All Documents", 3 ) );//[0] = one?//[1] +???//[2] =//[3] = + piecesPrint_r( Str_split( "All Documents", 4 ) );////////////////////////////////////////////////////////////////$SPL 1=Str_split( "Long" );Echo Count( $SPL 1 ).Php_eol; //4//[0] = L//[1] = o//[2] = n//[3] = gPrint_r( $SPL 1 );$SPL 2=Str_split( "X" );//1Echo Count( $SPL 2 ).Php_eol;//[0] = XPrint_r( $SPL 2 );$SPL 3=Str_split( "" );Echo Count( $SPL 3 ).Php_eol;//1//[0] =Print_r( $SPL 3 );$SPL 4=Str_split(  at );Echo Count( $SPL 4 ).Php_eol;//2//[0] = 2//[1] = 3Print_r( $SPL 4 );$SPL 5=Str_split( 2.3 );Echo Count( $SPL 5 ).Php_eol;//3//[0] = 2//[1] =.//[2] = 3Print_r( $SPL 5 );$SPL 6=Str_split( true );Echo Count( $SPL 6 ).Php_eol;//1//[0] = 1Print_r( $SPL 6 );$SPL 7=Str_split( NULL );Echo Count( $SPL 7 ).Php_eol;//1//[0] =Print_r( $SPL 7 );
See
    • http://php.net/manual/zh/function.str_split.php
All rights reserved

The Str_split () function of the PHP string is used

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.