separate string from integer

Discussion in 'PHP' started by bumbar, Apr 18, 2008.

  1. #1
    Hallo!

    I have this strings: "n0027285977", "an9100601010", "in3000008908"

    Is it possible that it to become following:

    
    $arr = array (n => '0027285977', an => '9100601010', in => '3000008908');
    
    PHP:
    Any Idia?
    Thanx ;)
     
    bumbar, Apr 18, 2008 IP
  2. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #2
    Use regular expressions, something like this:
    Note i havent tested this so may require a little tweaking
    
    preg_match("/(A-z+)(0-9+)/",$inputString,$retMatchArray);
    print_r($retMatchArray);
    
    Code (markup):
     
    m0nkeymafia, Apr 18, 2008 IP
  3. bumbar

    bumbar Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    thank you!

    but if I use this

    
    preg_match("/(A-z+)(0-9+)/",n0027285977,$retMatchArray);
    print_r($retMatchArray);
    
    PHP:
    The result is Array() .....
     
    bumbar, Apr 18, 2008 IP
  4. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #4
    Use quotes around the string :)

    i.e.
    
    [URL="http://www.php.net/preg_match"][COLOR=#000066]preg_match[/COLOR][/URL][COLOR=#66CC66]([/COLOR][COLOR=#FF0000]"/(A-z+)(0-9+)/"[/COLOR],"n0027285977",[COLOR=#0000FF]$retMatchArray[/COLOR][COLOR=#66CC66])[/COLOR];
    [URL="http://www.php.net/print_r"][COLOR=#000066]print_r[/COLOR][/URL][COLOR=#66CC66]([/COLOR][COLOR=#0000FF]$retMatchArray[/COLOR][COLOR=#66CC66])[/COLOR];
    
    Code (markup):
     
    m0nkeymafia, Apr 18, 2008 IP
  5. bumbar

    bumbar Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #5
    Hallo friend!

    Are you tested this? Nothing to result : Array () ... :D:D
     
    bumbar, Apr 18, 2008 IP
  6. m0nkeymafia

    m0nkeymafia Well-Known Member

    Messages:
    399
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    125
    #6
    No I said im not testing this, I don't have access to a server to test at the minute.
    The code ive given you is 99% correct, try mucking about with it yourself :)
     
    m0nkeymafia, Apr 18, 2008 IP