TD Posted February 26, 2008 Share Posted February 26, 2008 Hello! I need to split words from numbers. $code = "Johny234"; $split = explode(" ", $code); $codetxt = $split[0]; $codenr = $split[1]; Hope that someone can help me... many thanks! Quote Link to comment Share on other sites More sharing options...
paul2463 Posted February 26, 2008 Share Posted February 26, 2008 you will have to iterate over the string until you come across a number, then you will use substr() to break the string up Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 26, 2008 Share Posted February 26, 2008 If it is always a word then number combination, you could easily just do this: <?php $code = 'Johnny456'; preg_match('|^([a-z]+)([\d]+)$|i', $code, $match); $codetxt = $match[1]; $codenum = $match[2]; ?> Quote Link to comment Share on other sites More sharing options...
TD Posted February 26, 2008 Author Share Posted February 26, 2008 Yes i will have it always that word first and then the number comes. Many thanks it works very well! Cheers! Quote Link to comment Share on other sites More sharing options...
TD Posted February 26, 2008 Author Share Posted February 26, 2008 There may be a space between the word and number, what should i do, it wont work!??! Quote Link to comment Share on other sites More sharing options...
Orio Posted February 26, 2008 Share Posted February 26, 2008 Small modification... <?php $code = 'Johnny456'; preg_match('|^([a-z]+) ?([\d]+)$|i', $code, $match); $codetxt = $match[1]; $codenum = $match[2]; ?> Orio. Quote Link to comment Share on other sites More sharing options...
TD Posted February 26, 2008 Author Share Posted February 26, 2008 BIG BIG BIG Thanks Great community... Quote Link to comment 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.