1$myString = "9,admin@example.com,8";
2$myArray = explode(',', $myString);
3print_r($myArray);
1// Example 1
2$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
3$pieces = explode(" ", $pizza);
4echo $pieces[0]; // piece1
5echo $pieces[1]; // piece2
1<?php
2// It doesnt get any better than this Example
3$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
4$pieces = explode(" ", $pizza);
5echo $pieces[0]; // piece1
6echo $pieces[1]; // piece2
1// split() function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.
2// ALTERNATIVES: explode(), preg_split()
3
4// explode()
5// DESCRIPTION: Breaks a string into an array.
6// explode ( string $separator , string $string , int $limit = PHP_INT_MAX ) : array
7$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
8$pieces = explode(" ", $pizza);
9echo $pieces[0]; // piece1
10echo $pieces[1]; // piece2
11
12// preg_split()
13// DESCRIPTION: Split the given string by a regular expression.
14// preg_split ( string $pattern , string $subject , int $limit = -1 , int $flags = 0 ) : array|false
15$keywords = preg_split("/[\s,]+/", "hypertext language, programming");
16print_r($keywords);
17// output:
18Array
19(
20 [0] => hypertext
21 [1] => language
22 [2] => programming
23)
1You can use this following function
2
3 function str_rsplit($string, $length)
4{
5 // splits a string "starting" at the end, so any left over (small chunk) is at the beginning of the array.
6 if ( !$length ) { return false; }
7 if ( $length > 0 ) { return str_split($string,$length); } // normal split
8
9 $l = strlen($string);
10 $length = min(-$length,$l);
11 $mod = $l % $length;
12
13 if ( !$mod ) { return str_split($string,$length); } // even/max-length split
14
15 // split
16 return array_merge(array(substr($string,0,$mod)), str_split(substr($string,$mod),$length));
17}
18
19
20$str = '123456789';
21str_split($str,5); // return: {"12345","6789"}
22str_rsplit($str,5); // return: {"12345","6789"}
23str_rsplit($str,-7); // return: {"12","3456789"}
24