Jump to content

splitting a string


mrithula

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.