String Splitting Demo

str_split v explode v split v preg_split

Original String: Melksham    Town      12,300    Petty   Gray   2013


Using str_split
Array
(
    [0] => M
    [1] => e
    [2] => l
    [3] => k
    [4] => s
    [5] => h
    [6] => a
    [7] => m
    [8] =>  
    [9] =>  
    [10] =>  
    [11] =>  
    [12] => T
    [13] => o
    [14] => w
    [15] => n
    [16] =>  
    [17] =>  
    [18] =>  
    [19] =>  
    [20] =>  
    [21] =>  
    [22] => 1
    [23] => 2
    [24] => ,
    [25] => 3
    [26] => 0
    [27] => 0
    [28] =>  
    [29] =>  
    [30] =>  
    [31] =>  
    [32] => P
    [33] => e
    [34] => t
    [35] => t
    [36] => y
    [37] =>  
    [38] =>  
    [39] =>  
    [40] => G
    [41] => r
    [42] => a
    [43] => y
    [44] =>  
    [45] =>  
    [46] =>  
    [47] => 2
    [48] => 0
    [49] => 1
    [50] => 3
)

Using explode
Array
(
    [0] => Melksham
    [1] => 
    [2] => 
    [3] => 
    [4] => Town
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => 12,300
    [11] => 
    [12] => 
    [13] => 
    [14] => Petty
    [15] => 
    [16] => 
    [17] => Gray
    [18] => 
    [19] => 
    [20] => 2013
)

Using split
Array
(
    [0] => Melksham
    [1] => 
    [2] => 
    [3] => 
    [4] => Town
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => 12,300
    [11] => 
    [12] => 
    [13] => 
    [14] => Petty
    [15] => 
    [16] => 
    [17] => Gray
    [18] => 
    [19] => 
    [20] => 2013
)

Using preg_split
Array
(
    [0] => Melksham
    [1] => Town
    [2] => 12,300
    [3] => Petty
    [4] => Gray
    [5] => 2013
)
discounted
discounted


Training sample © 2024, WELL HOUSE CONSULTANTS LTD
This is http://www.wellho.net/demo/splitting.php
See source code here • More examples - same topic here
Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
Phone: +44 (0) 1225 708 225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net