Re: serialize() and special ANSI characters
| From: | Youri LACAN-BARTLEY | Date: | Mon, 19 Feb 2007 16:29:53 +0000 |
| Subject: | Re: serialize() and special ANSI characters | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-249026@lists.php.net to get a copy of this message | ||
Roman Neuhauser wrote:
# ylacan@teicam.com / 2007-02-19 15:56:15 +0100:I'm probably just running into so encoding issues with the CSV files I'm using on which I have no control whatsoever.I'm just curious to find out if I'm the only person to have bumped into this kind of issue with serialize/unserialize. When I try and serialize an array containing a string value with the "?" character (alt+241 ASCII) such as : "120GB 2X512MB 15.4IN DVD?RW VHP FR" The resulting serialized array is truncated. ie. I would obtain : "a:17:{i:0;s:1:"A";i:1;s:7:"TOSHIBA";i:2;s:4:"3740";i:3;s:7:"404D862";i:4;s:31:"SATELLITE A100-044 CD/T2060-1.6";i:5;s:35:"120GB 2X512MB 15.4IN DVD" As you can see serialization seems to stall as soon as the "?" character shows up.I don't see the effect you're mentioning, but this is on FreeBSD, so perhaps there's a problem on Windows. I don't really believe it, though, and would hazard a guess you're running into display problems with your browser. Another thing to mention is that ASCII only goes up to 127. You may desire for ASCII 241 to mean +/-, but n-tilde is also a popular interpretation... Use a character set which actually includes +/- as a single character, and an encoding that can handle that charset.
The following test fails in 5.2.1:
<?php
class serializeASCII241 extends Tence_TestCase
{
function testTruncates()
{
return $this->assertEquals(
"120GB 2X512MB 15.4IN DVD",
serialize("120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR")
);
}
}
?>
I'd just like to point out that your test will fail systematically unless you use something like this :
function testTruncates()
{
$string = "120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR";
return $this->assertEquals(
"s:" . strlen($string) . ":\"120GB 2X512MB 15.4IN DVD",
serialize("120GB 2X512MB 15.4IN DVD" . chr(241) . "RW VHP FR")
);
}