View Single Post
Old 12-15-2012, 09:07 PM   PM User | #20
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by doubledee View Post
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote