Quote:
Originally Posted by tangoforce
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
|
Wow! Thanks for all of the examples!!
Quote:
|
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.
|
But technically that is true of anything passed through a Form, right?
Since I am just passing back a listing of all PM ID's to the same script so it knows which Messages need to be updated, and since the "pmID" is an Integer, then as long as I sanitize things by casting to an Integer, and using Prepared Statements - which is actually the only way I know how to do database stuff - then I assume that I will be okay from a security standpoint?!
BTW, you guys please don't leave me just yet.
I need to re-read everyone's suggestions, and also go to the PHP Manual and read up on all of this,
and then try and piece it all together into a working script?!
I'll likely have some more questions here in a a little bit!!
But thanks for all of the help so far!!
Debbie