Jump to content

Split "Word"


rlpj

Recommended Posts

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....

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.