FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » implode/explode vs serialize/unserialize
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: implode/explode vs serialize/unserialize [message #178309 is a reply to message #178303] Wed, 30 May 2012 20:34 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
bill wrote:

> On 5/29/2012 10:19 AM, Erwin Moller wrote:
>> On 5/29/2012 3:24 PM, bill wrote:
>>> Would one of the more knowledgeable folk discuss when it is
>>> appropriate
>>> to use implode/explode and when it is appropriate to use
>>> serialize/unserialize.
>>>
>>> It seems that for 1D arrays implode is better in that is only
>>> adds 1
>>> character per array element and serialize adds many.
>>>
>>> For objects, serialze is the only way to go.
>>>
>>> in between ?
>>>
>>> bill
>>
>> That is a vague question without more context.
>> Shooting from the hip I would suggest you use serialize only if
>> you need to store/transport a complex structure.
>> And use implode and explode only when you want to create a string
>> from a simple array (no arrays in arrays), and the other way around.

Utter nonsense.

> Your shot from the hip is exactly what I was looking for - thanks.

No it is not. The problem with that approach is that implode() is _not_
generally reversible with explode(), even in a simple, one-dimensional array
where all elements are of the same type.

It does not work if the array elements are of different type or are not
strings (because the values are type-converted to string, and exploding a
string results in array of string elements), and it does not work if the
delimiter (say, `,') is part of any array string element, assuming that all
values are strings already. And if you knew exactly what was in an array,
you would not need to implode() it in the first place.

So if you want to preserve a data structure in string form for later
restore, use serialize() and unserialize(), nothing else.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: CFP - DEIS2012 - Czech Republic - SDIWC
Next Topic: PHP Concatenate
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Oct 06 14:37:40 GMT 2024

Total time taken to generate the page: 0.03825 seconds