Serializing and Unserializing
Posted: Tue Jun 19, 2007 6:23 am
Ok so I am making a multi lingual website and I am saving all the dynamic text as a serialized array in the database then unserializing it when I need to display it. Everything is going fine with this method, except this 1 thing is not working. I have this long string with HTML and text in it and I am trying to save it in a serialized array. No problems there but when I unserialize it, I get an error. I have tried everything to no avail.
Here is a simplified test case that is failing. I start with this code:
Then that outputs this:
No problem. But then I copy that string and try to unserialize it and I get an error. I do exactally this code:
and I get this error:
Notice: unserialize() [function.unserialize]: Error at offset 1585 of 1690 bytes in /var/www/html/test.php on line 58
And as I understand this error it means the byte count is wrong somewhere but I don't understand why in the world is it wrong? I am changing nothing from the original serialized array, this does not make sense and of all the string I have been serializing with lots of HTML and other sorts of crazy stuff this is the only one that is giving me any trouble anywhere. Am I missing something stupid?
Here is a simplified test case that is failing. I start with this code:
Code: Select all
$str = 'Follow these steps to sign up to NoIqPoker, and to get included in their VIP Cash Bonus program. iPoker rakeback is not available, but this VIP Cash Bonus program is a very good alternative.
<br />
<br />
<img src="images/rb_bullet_orange.gif" border="0" /><b>Example:</b> <font color="#FF0000">$1</font> in tournament fees equals <font color="#FF0000">$0.39</font> VIP Cash Bonus, when you are at VIP Level Black and get 40 FPP. See the <a href="noiqpoker/offers/">NoiQPoker Offers</a> page for VIP tables and a bonus calculator.
<h2>NoIqPoker VIP Cash Bonus Program Sign Up</h2>
<ol>
<li>
<a href="poker-forum/register.php">Register an account</a> to Rakeback.com website and log in.
</li>
<li>
Download and install NoIqPoker software:
<br />
<img src="images/rb_bullet_orange.gif" border="0" alt="" /><a href="http://www.noiqpoker.com/download.html" target="_blank">www.noiqpoker.com/download.html</a>
</li>
<li>
Open NoIqPoker and click <b>Create Account</b>.
<br />
<img src="images/rb_bullet_orange.gif" border="0" alt="" />Enter our code <b>RAKECOM</b> in the <i>Signup code</i> field.
<br />
<br />
<img src="images/noiqpoker-code.jpg" border="0" alt="NoIqPoker Signup code" width="378" height="125" />
</li>
</ol>
<h2>Submit NoIqPoker Sign Up Form</h2>
After opening your NoIqPoker account, please submit your <b>NoIqPoker Username</b> to us with the form below. You need to be logged in to our website to do this. Our Support will then verify your NoIqPoker sign up and send you a confirmation email.';
$arr = array('en' => $str, 'br' => '', 'cn' => '', 'de' => '', 'es' => '', 'it' => '', 'se' => '');
$thing = serialize($arr);
echo $thing;Code: Select all
a:7:{s:2:"en";s:1742:"Follow these steps to sign up to NoIqPoker, and to get included in their VIP Cash Bonus program. iPoker rakeback is not available, but this VIP Cash Bonus program is a very good alternative.
<br />
<br />
<img src="images/rb_bullet_orange.gif" border="0" /><b>Example:</b> <font color="#FF0000">$1</font> in tournament fees equals <font color="#FF0000">$0.39</font> VIP Cash Bonus, when you are at VIP Level Black and get 40 FPP. See the <a href="noiqpoker/offers/">NoiQPoker Offers</a> page for VIP tables and a bonus calculator.
<h2>NoIqPoker VIP Cash Bonus Program Sign Up</h2>
<ol>
<li>
<a href="poker-forum/register.php">Register an account</a> to Rakeback.com website and log in.
</li>
<li>
Download and install NoIqPoker software:
<br />
<img src="images/rb_bullet_orange.gif" border="0" alt="" /><a href="http://www.noiqpoker.com/download.html" target="_blank">www.noiqpoker.com/download.html</a>
</li>
<li>
Open NoIqPoker and click <b>Create Account</b>.
<br />
<img src="images/rb_bullet_orange.gif" border="0" alt="" />Enter our code <b>RAKECOM</b> in the <i>Signup code</i> field.
<br />
<br />
<img src="images/noiqpoker-code.jpg" border="0" alt="NoIqPoker Signup code" width="378" height="125" />
</li>
</ol>
<h2>Submit NoIqPoker Sign Up Form</h2>
After opening your NoIqPoker account, please submit your <b>NoIqPoker Username</b> to us with the form below. You need to be logged in to our website to do this. Our Support will then verify your NoIqPoker sign up and send you a confirmation email.";s:2:"br";s:0:"";s:2:"cn";s:0:"";s:2:"de";s:0:"";s:2:"es";s:0:"";s:2:"it";s:0:"";s:2:"se";s:0:"";}Code: Select all
$str2 = 'a:7:{s:2:"en";s:1742:"Follow these steps to sign up to NoIqPoker, and to get included in their VIP Cash Bonus program. iPoker rakeback is not available, but this VIP Cash Bonus program is a very good alternative.
<br />
<br />
<img src="images/rb_bullet_orange.gif" border="0" /><b>Example:</b> <font color="#FF0000">$1</font> in tournament fees equals <font color="#FF0000">$0.39</font> VIP Cash Bonus, when you are at VIP Level Black and get 40 FPP. See the <a href="noiqpoker/offers/">NoiQPoker Offers</a> page for VIP tables and a bonus calculator.
<h2>NoIqPoker VIP Cash Bonus Program Sign Up</h2>
<ol>
<li>
<a href="poker-forum/register.php">Register an account</a> to Rakeback.com website and log in.
</li>
<li>
Download and install NoIqPoker software:
<br />
<img src="images/rb_bullet_orange.gif" border="0" alt="" /><a href="http://www.noiqpoker.com/download.html" target="_blank">www.noiqpoker.com/download.html</a>
</li>
<li>
Open NoIqPoker and click <b>Create Account</b>.
<br />
<img src="images/rb_bullet_orange.gif" border="0" alt="" />Enter our code <b>RAKECOM</b> in the <i>Signup code</i> field.
<br />
<br />
<img src="images/noiqpoker-code.jpg" border="0" alt="NoIqPoker Signup code" width="378" height="125" />
</li>
</ol>
<h2>Submit NoIqPoker Sign Up Form</h2>
After opening your NoIqPoker account, please submit your <b>NoIqPoker Username</b> to us with the form below. You need to be logged in to our website to do this. Our Support will then verify your NoIqPoker sign up and send you a confirmation email.";s:2:"br";s:0:"";s:2:"cn";s:0:"";s:2:"de";s:0:"";s:2:"es";s:0:"";s:2:"it";s:0:"";s:2:"se";s:0:"";}';
$thing = unserialize($str2);
print_r($thing);
die();Notice: unserialize() [function.unserialize]: Error at offset 1585 of 1690 bytes in /var/www/html/test.php on line 58
And as I understand this error it means the byte count is wrong somewhere but I don't understand why in the world is it wrong? I am changing nothing from the original serialized array, this does not make sense and of all the string I have been serializing with lots of HTML and other sorts of crazy stuff this is the only one that is giving me any trouble anywhere. Am I missing something stupid?