Splitting a name based on Capital letters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpmel
    New Member
    • Oct 2007
    • 69

    Splitting a name based on Capital letters

    I have a username that is Joined together as follows
    JohnSmith
    The first letter in each of the first and last name is Capital
    Can some one help me write a php function to split the name and get John Smith.
    I am not sure what functions to use.
  • chinmay4u
    New Member
    • Dec 2007
    • 5

    #2
    here is the code [php]
    <?php
    function isuppercase($ch ar)
    {
    if(ord($char)>6 4 && ord($char)<91)
    {
    return TRUE;
    }
    elseif(ord($cha r)>96 && ord($char)<123)
    {
    return FALSE;
    }
    else
    {
    return 'Non Alpha Character';
    }
    }

    $string = 'JohsnSmithAndH isBrotherWentTo London';
    for($i=0; $i<strlen($stri ng); $i++)
    {

    if( ($isupper = isuppercase($st ring{$i})) !== 'Non Alpha Character' )
    {
    if($isupper)
    {
    echo '<br>';
    }
    echo ' <strong>'.$stri ng{$i}.'</strong> ';
    }
    else
    {
    echo 'Is not an alpha character';
    }
    }
    ?>[/php]
    Last edited by ronverdonk; Mar 23 '08, 04:51 PM. Reason: code tags

    Comment

    • subsquare
      New Member
      • Mar 2008
      • 1

      #3
      Originally posted by phpmel
      I have a username that is Joined together as follows
      JohnSmith
      The first letter in each of the first and last name is Capital
      Can some one help me write a php function to split the name and get John Smith.
      I am not sure what functions to use.
      Or in one line like this:
      [php]preg_replace('/[A-Z]/', ' $0', $text_tp_use);[/php]
      Last edited by ronverdonk; Mar 23 '08, 04:52 PM. Reason: code tags

      Comment

      • satas
        New Member
        • Nov 2007
        • 82

        #4
        Originally posted by subsquare
        Or in one line like this:
        [php]preg_replace('/[A-Z]/', ' $0', $text_tp_use);[/php]
        Wow, that is awesome!

        Comment

        Working...