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? Quote 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 Quote 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... Quote Link to comment https://forums.phpfreaks.com/topic/215264-splitting-a-string/#findComment-1119700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.