rlpj Posted February 18, 2008 Share Posted February 18, 2008 My first post, did a search could not find anything I am trying to accomplish. Here it goes. I have a word as follows: eri0Ipkt There is no logical divider between words just a key word. I want to break it into an array or individual variables, either is fine but capture both words a seperate variables.. The key is "Ipkt" . So I would have : $Var0 = Ipkt; $Var1 = eri0; or $array[0] = $Var0; $array[1] = $Var1; if I do this: $test = explode("Ipkt", $key); I get this: Array ( [0] => eri0 [1] => ) Thanks in advance.... Quote Link to comment Share on other sites More sharing options...
Rithiur Posted February 18, 2008 Share Posted February 18, 2008 Well, since you know the word you used to split the string, you could just manually add it to the array after splitting it. Of course, you can also use preg_split with couple flags like: preg_split('/(Ipkt)/', 'eri0Ipkt', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) Quote Link to comment Share on other sites More sharing options...
p2grace Posted February 18, 2008 Share Posted February 18, 2008 Is it always the same number of characters, or are there ever characters following Ipkt? If there isn't you could just do something like: $test = substr($key,-4); // This will give you the ipkt, and then just create a another substring to find whatever was in front of it. Quote Link to comment Share on other sites More sharing options...
rlpj Posted February 18, 2008 Author Share Posted February 18, 2008 Thanks for the tip.. Yes in this case it is always the exact number of chars with no tailing entries. Ipkt. I wanted a generic one where I have other keys I could apply the same routine to. I am trying to make a generic function where everything past eri0 is the key, garb it spilt and return the 2 variables. There is nothing after he keys and nothing before the eri0. Example: eri0Ipkt eri0Opkt eri0InKB eri0InDtSz eri0InOvH eri0OuKB eri0OuDtSz eri0OuOvH eri0IErr eri0OErr eri0Coll eri0NoCP eri0Defr Again, thank for your help on this, very much appreciated. I will give both a try . 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.