str_split

We can split a string with fixed intervals ( without using any delimiter ) by using PHP str_split command. The output we will get an array with broken string of fixed length. This breaking of string is different than explode as no delimiter is used to split the string. Here is the syntax.

str_split(string, integer of length )

Let us try one example

$string="Welcome to Plus2net Php section";
print_r(str_split($string,5));

The output is here

Array ( [0] => Welco [1] => me to [2] => Plus [3] => 2net [4] => Php s [5] => ectio [6] => n )

Let us see if we don't use any length integer. The output array will have elements of single char. Means it will be broken across each char or the default value will be 1.

$string="Welcome to Plus2net Php section";
print_r(str_split($string));

Output is here

Array ( [0] => W [1] => e [2] => l [3] => c [4] => o [5] => m [6] => e [7] => [8] => t
[9] => o [10] => [11] => P [12] => l [13] => u [14] => s [15] => 2 [16] => n [17] => e
[18] => t [19] => [20] => P [21] => h [22] => p [23] => [24] => s [25] => e [26] => c
[27] => t [28] => i [29] => o [30] => n )



plus2net.com




PHP String Functions

Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer