friend_test2_2_Mobile
I have to split this String
on the basis of _
in php
and acess data according to postions.
How do we split and access these in php
Please Help !!!
friend_test2_2_Mobile
I have to split this String
on the basis of _
in php
and acess data according to postions.
How do we split and access these in php
Please Help !!!
you're looking for explode
.
$parts = explode('_', 'friend_test2_2_mobile');
// $parts = array('friend','test2','2','mobile');
// $parts[0] = 'friend'
// $parts[1] = 'test2'
// $parts[2] = '2'
// $parts[3] = 'mobile'
Or if you want more control, you can use list
:
list($name,$foo,$id,$device) = explode('_', 'friend_test2_2_mobile')
// $name = 'friend'
// $foo = 'test2'
// $id = '2'
// $device = 'mobile'