Connecting Tech Pros Worldwide Forums | Help | Site Map

combining serialized data

Jon Slaughter
Guest
 
Posts: n/a
#1: May 16 '07
I have some data I want to serialize but I want to combine them.

something like
serialize($data1).serialize($data2)

and then later on I need to deserialize them back into two seperate
variables. I'm not sure how I can go about this? Obviously I could seperate
them by some token and use that but I'm not sure how safe it is. Is there a
better method? or a token that I know I can used.

I guess I could do something like this

$str = serialize(array(serialize($data1), serialize($data2)))

then
$t = unserialize($str);
$data1 = unserialize($t[0]);
$data2 = unserialize($t[1]);

but seems like the long way around?

Thanks,
Jon



jmark@fastermail.com
Guest
 
Posts: n/a
#2: May 17 '07

re: combining serialized data


On May 16, 3:06 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
Quote:
I have some data I want to serialize but I want to combine them.
>
something like
serialize($data1).serialize($data2)
>
and then later on I need to deserialize them back into two seperate
variables. I'm not sure how I can go about this? Obviously I could seperate
them by some token and use that but I'm not sure how safe it is. Is there a
better method? or a token that I know I can used.
>
I guess I could do something like this
>
$str = serialize(array(serialize($data1), serialize($data2)))
>
then
$t = unserialize($str);
$data1 = unserialize($t[0]);
$data2 = unserialize($t[1]);
>
but seems like the long way around?
>
Thanks,
Jon
You can simply make a new array and then serialize the array
$combinedData - array($data1, data2);
serialize($combinedData)

jmark@fastermail.com
Guest
 
Posts: n/a
#3: May 17 '07

re: combining serialized data


On May 16, 3:06 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
Quote:
I have some data I want to serialize but I want to combine them.
>
something like
serialize($data1).serialize($data2)
>
and then later on I need to deserialize them back into two seperate
variables. I'm not sure how I can go about this? Obviously I could seperate
them by some token and use that but I'm not sure how safe it is. Is there a
better method? or a token that I know I can used.
>
I guess I could do something like this
>
$str = serialize(array(serialize($data1), serialize($data2)))
>
then
$t = unserialize($str);
$data1 = unserialize($t[0]);
$data2 = unserialize($t[1]);
>
but seems like the long way around?
>
Thanks,
Jon
You can simply make one array and serialize it
$combinedData = array($data1, $data2);
serialize($combinedData)


jmark@fastermail.com
Guest
 
Posts: n/a
#4: May 17 '07

re: combining serialized data


On May 16, 9:24 pm, j...@fastermail.com wrote:
Quote:
On May 16, 3:06 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
>
>
>
>
>
Quote:
I have some data I want to serialize but I want to combine them.
>
Quote:
something like
serialize($data1).serialize($data2)
>
Quote:
and then later on I need to deserialize them back into two seperate
variables. I'm not sure how I can go about this? Obviously I could seperate
them by some token and use that but I'm not sure how safe it is. Is there a
better method? or a token that I know I can used.
>
Quote:
I guess I could do something like this
>
Quote:
$str = serialize(array(serialize($data1), serialize($data2)))
>
Quote:
then
$t = unserialize($str);
$data1 = unserialize($t[0]);
$data2 = unserialize($t[1]);
>
Quote:
but seems like the long way around?
>
Quote:
Thanks,
Jon
>
You can simply make a new array and then serialize the array
$combinedData - array($data1, data2);
serialize($combinedData)- Hide quoted text -
>
- Show quoted text -
There was a typo there. The statement should have been this way
$combinedData = array($data1, $data2);

Jon Slaughter
Guest
 
Posts: n/a
#5: May 17 '07

re: combining serialized data



<jmark@fastermail.comwrote in message
news:1179403236.320078.38740@p77g2000hsh.googlegro ups.com...
Quote:
On May 16, 3:06 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:
Quote:
>I have some data I want to serialize but I want to combine them.
>>
>something like
>serialize($data1).serialize($data2)
>>
>and then later on I need to deserialize them back into two seperate
>variables. I'm not sure how I can go about this? Obviously I could
>seperate
>them by some token and use that but I'm not sure how safe it is. Is
>there a
>better method? or a token that I know I can used.
>>
>I guess I could do something like this
>>
>$str = serialize(array(serialize($data1), serialize($data2)))
>>
>then
>$t = unserialize($str);
>$data1 = unserialize($t[0]);
>$data2 = unserialize($t[1]);
>>
>but seems like the long way around?
>>
>Thanks,
>Jon
>
You can simply make one array and serialize it
$combinedData = array($data1, $data2);
serialize($combinedData)
>
Thanks,
Jon


Closed Thread


Similar PHP bytes