mrithula Posted October 6, 2010 Share Posted October 6, 2010 The sample string is KmSO4 Every upper case alphabet should be identified and splitted until another upper case alphabet comes. the string should be splitted so that output array looks like this Array ( [0] => Km [1] => S [2]=>O4 ) can any one help regarding this issue? Link to comment https://forums.phpfreaks.com/topic/215264-splitting-a-string/ Share on other sites More sharing options...
salathe Posted October 6, 2010 Share Posted October 6, 2010 You could use a regular expression to look for points in the string which have a capital letter immediately following it. How familiar are you with regular expressions? (It's OK to say not at all!) $array = preg_split('/(?!^)(?=[A-Z])/', 'KmSO4'); If that just looks like an indecipherable mess, let us know. The job can likely also be done with functions that you are more familiar with (do let us know!). See also: http://php.net/reference.pcre.pattern.syntax http://php.net/preg_split Link to comment https://forums.phpfreaks.com/topic/215264-splitting-a-string/#findComment-1119511 Share on other sites More sharing options...
mrithula Posted October 7, 2010 Author Share Posted October 7, 2010 Thank you....I have written 10 lines of code to achieve this....this is quite nice... Link to comment https://forums.phpfreaks.com/topic/215264-splitting-a-string/#findComment-1119700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.