Quote:
Originally Posted by doubledee
In the mean time, can you please explain more about using Implode/Explode versus Serialize/Unserialize and how I'd go about that?
|
Serialize basically converts a variable into a textual description of it.
Look at this:
PHP Code:
$Array[] = 'This '; // Note I've left space on end
$Array[] = 'is ';
$Array[] = 'a ';
$Array[] = 'test ';
$Output = serialize($Array);
print $Output;
$Output would be: a:4:{i:0;s:5:"This ";i:1;s:3:"is ";i:2;s:2:"a ";i:3;s:5:"test ";}
a: array with 4 parts
i:0 integer / index is zero
s:5 String with 5 characters
etc
See it in action on codepad:
http://codepad.org/n0Wgrras
Explode / implode:
PHP Code:
$Array[] = 'This'; //No spaces as we can use implode for that
$Array[] = 'is';
$Array[] = 'a';
$Array[] = 'test';
$Output = implode(' ', $Array);
print $Output; // This is a test
See it on codepad:
http://codepad.org/eVuw8dDN
Explode does the opposite - breaking up a string by the specified character:
PHP Code:
$Input = 'This is a test';
$Array = explode(' ', $Input);
var_dump($Array);
Outputs:
array(4) {
[0]=>
string(4) "This"
[1]=>
string(2) "is"
[2]=>
string(1) "a"
[3]=>
string(4) "test"
}
See it on Codepad:
http://codepad.org/a2noxZWS
Personally I recommend going with Andys explode/implode as it's simpler. Using the serialisation would make it a bit more complex but it would be slightly (though still possible) for anyone to change those values.