jasonc Posted August 3, 2008 Share Posted August 3, 2008 $string = "JoeBloggs"; or $string = "MarySmith"; how do i get the first part of the string before the second upper case letter? Mary or Joe thanks PHP5 server Link to comment https://forums.phpfreaks.com/topic/117926-get-part-of-string-before-the-second-upper-case-character/ Share on other sites More sharing options...
JasonLewis Posted August 3, 2008 Share Posted August 3, 2008 Well, I suppose you could do it like this: $string = "JoeBloggs"; $split = preg_match_all("#[A-Z]{1}[a-z]+#",$string,$match); print_r($match); Link to comment https://forums.phpfreaks.com/topic/117926-get-part-of-string-before-the-second-upper-case-character/#findComment-606584 Share on other sites More sharing options...
PHPTOM Posted August 3, 2008 Share Posted August 3, 2008 <?PHP $string = "JoeBloggs"; $spliter = split(",",substr(preg_replace("/([A-Z])/",',\\1',$string),1)); $forename = $spliter[0]; $surname = $spliter[1]; ?> This can also be used if $string = "JoeBloggsWithMoreCaps"; Link to comment https://forums.phpfreaks.com/topic/117926-get-part-of-string-before-the-second-upper-case-character/#findComment-606588 Share on other sites More sharing options...
jasonc Posted August 3, 2008 Author Share Posted August 3, 2008 thanks for that, i really appreciate it. Link to comment https://forums.phpfreaks.com/topic/117926-get-part-of-string-before-the-second-upper-case-character/#findComment-606596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.