Help /w string manipulation<

liunx

Guest
I have a page with one form & many select boxes. They are split up in such a fashion that each "owner" has to choose 4 "drivers", so I end up with a 5 column layout, the 1st column shows the name of the "owner" (filled in automatically) , and each subsequent column is a select box from which the "owner" must choose a "driver". Upon completion of the form, it is sent to a php page which processes the form data.

I want to be able to distinguish each select box from another so I created a formatted string which included both the index of the "owner" and the number of the "driver" for that particular select box. For each owner, there would be 4 select boxes, so the name of each select box has the format:

ownerXdriver1
ownerXdriver2
ownerXdriver3
ownerXdriver4

the next would be

ownerYdriver1
ownerYdriver2
ownerYdriver3
ownerYdriver4

The value of each select box will the index of the driver which was chosen (this index actually refs to an index in a database).

My problem is when processing the form, I have to separate the ownerIndex and the driver number so that I will be able to use these values to update a database. So in the following:


owner45driver3


I want to be able to pull out '45' and '3'. Then if the "value" of this particular select box was '33', I'd know that:

For ownerIndex '45' I need to make his '3rd' driver the driver whose index is '33'.

My problem is, but because both numbers can be anywhere from 1 to 99, I can't assume that the string is of a certain length, so substr won't work. In other words, in the above '3' is the 13th character, but if I had

owner4driver3

it's not the 12th letter. What functions could I use to isolate the numbers more easily?Is there any way you can make it so that instead of having 'owner45driver3', you can have 'owner-45-driver-3'? If you can do that, then you can just explode it, and you'll always know that the second and fourth. You could do something like this, I may be way off on what you want though:



$id = "owner-45-driver-3";
$pieces = explode("-", $id);
echo $pieces[0]; // owner
echo $pieces[1]; // 45
echo $pieces[2]; // driver
echo $pieces[3]; // 3


I dunno, something like thatYep I sure can do that! Looks like that will work much better. I'll try it out, thanks!Good luck, hope it works out.
 
Back
Top