PDA

View Full Version : PHP Explode/Split...?



iUnknown
22-10-2008, 09:05 PM
Hello,

I need a little help splitting up/exploding a variable in PHP.

Say this is my variable:

2;C;/Diamond/0/DiamondM2/thedeath-v2.321//;C;/Diamond/16/DiamondM2/thedeath-v2.321//;

I can do:


$u = split(";",$mylongvariable);
$u = split("/",$u[4]);
$user = $u[2];

And $user will = 16, the part of the string that I'm after.

However for this variable:

2;Sting/99/0/GOOD;Sting/0/6/GOOD;

I need to get the 6 (nearish the end). How would I do that?

Thanks and +rep to correct answer.

CS-dude
22-10-2008, 09:21 PM
Hello,

I need a little help splitting up/exploding a variable in PHP.

Say this is my variable:

2;C;/Diamond/0/DiamondM2/thedeath-v2.321//;C;/Diamond/16/DiamondM2/thedeath-v2.321//;

I can do:


$u = split(";",$mylongvariable);
$u = split("/",$u[4]);
$user = $u[2];

And $user will = 16, the part of the string that I'm after.

However for this variable:

2;Sting/99/0/GOOD;Sting/0/6/GOOD;

I need to get the 6 (nearish the end). How would I do that?

Thanks and +rep to correct answer.
Hey,

I'm having a little trouble figuring out why on earth you want all this?
But since you asked for the second example, I think, off my head this should work (as long as I counted my /'s correctly)



$u = split("/","2;Sting/99/0/GOOD;Sting/0/6/GOOD;");
$out= $u[5];


CS-Dude

iUnknown
22-10-2008, 09:28 PM
That might of worked, but I managed to do it myself with this:



$u = split(";",$mylongvariable);
$u = split("/",$u[2]);
$user = $u[2];


I just had to think about it a bit. It helps me to lay it out in a post sometimes :P

Thanks for your efforts though, +rep.

Thread closed.

Want to hide these adverts? Register an account for free!