Jump to content

unserialize issues


taith

Recommended Posts

hey everyone... i'm having some issues with unserialize... for some reason... when it fails(for some reason?) its not outputing any errors or any information... anyone know what might be going on here?

 

<?php
$array='a:1:{i:0;a:2:{s:4:"text";s:51:"<em><span style="color: #ff6600;">adf</span></em>";s:8:"imageloc";s:4:"left";}}';
print_r(unserialize($array));
?>

Link to comment
Share on other sites

dave420 is correct. You should not try and make up a serialize string by hand (if that's what you did).

 

You're not displaying PHP notices. Turn them on with error_reporting() or changing php.ini. If you had it on, you would have seen a message like the following which would have helped you:

 

Notice: script.php line xxx - unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 82 of 120 bytes

 

Link to comment
Share on other sites

ok... that one works for that... and no, i'm not setting it manually... i'm $string=serialize(html_entities($_SESSION[var])); then storing in the database... and its doing that on EVERY  entery...

 

and yes... that does give the warning... but thats completly unhelpful lol it says that theres an error, but not why theres an error...

Link to comment
Share on other sites

I'd suggest to spare yourself the trouble and make the array in an actual array, then serialize when you've finished changing the contents.  It might even be quicker that way.

 

i am... this is a dynamic form content... it should be allowing the user to save/load without adversely affecting the way the site works... on save it html_entities(), serializes, and enters into the database, then... on load, it pulls from the database, unserializes, and... crashes

Link to comment
Share on other sites

ok... that one works for that... and no, i'm not setting it manually... i'm $string=serialize(html_entities($_SESSION[var])); then storing in the database... and its doing that on EVERY  entery...

 

and yes... that does give the warning... but thats completly unhelpful lol it says that theres an error, but not why theres an error...

 

Are you sure you're doing

 

<?php
$string=serialize(html_entities($_SESSION[var]));
?>

 

and not

 

<?php

$string=html_entities(serialize($_SESSION[var]));

?>

 

?

Link to comment
Share on other sites

yes, the content is being converted properly... and the serializer is serializing it properly...

 

actual code from site

 

save:

    $temail=serialize(html_entities($_SESSION[email]));

 

load:

    $_SESSION[email]=unserialize($r[email]);

 

heres "another" one of a few that arnt working...

$r[email]='
a:3:{
i:0;a:2:{
  s:4:"text"; s:903:"<br style="text-align:center;"><span style="font-family:arial,helvetica,sans-serif; font-size:medium;"><font size="5"><strong>Welcome to the first edition of the <br>Blue Banana Marketing Newsletter<br></strong></font><br>With one year in business - HAPPY BIRTHDAY TO US - and a growing client base...I am excited to start sharing marketing tips.<br><br><strong>Thank you to all current Blue Banana clients for your business and referrals.</strong>  Ninety per cent of our new clients come by referrals from existing clients - which says what we’re doing here at Blue Banana is effective and exceeding client expectations.<br><br><font color="#333399"><strong><font color="#000099">We're interested in building strong lifelong relationships one person, one business at a time. Thank you for helping.</font><br><br></strong></font></span>";
  s:8:"imageloc";s:4:"left";
}
i:1;a:3:{
  s:4:"text"; s:953:"<span style="font-size: medium;"><strong><font color="#993366"><font face="helvetica">Only 5 spots remaining for the:<br></font><font face="helvetica"><br>Small Business Marketing 101 Workshop</font><font face="helvetica"><br><br>Thursday, February 28, 2008 at <br>9 a.m. – 12 p.m. at the <br>Quality Champlain Hotel<br>Cost is $45/person.<br><br></font></font></strong></span><br><span style="font-family: helvetica; font-size: medium;">REGISTER TODAY!</span><span style="font-size: medium;"><strong><font color="#993366"><font face="helvetica"><br>For more information go to:</font></font></strong></span><br><span style="font-family: helvetica; color:#0000ff;font-size:small;"><font color="#993366"><a href="http://www.bluebananamarketing.ca/">http://www.bluebananamarketing.ca<br><br></a></font></span><strong><br></strong>";
  s:8:"imageloc"; s:4:"left";
  s:8:"pictures";a:1:{
   i:0;a:2:{
    s:3:"url"; s:32:"cimages/Osctob8GY7o20egxiOtF.gif";
    s:4:"name"; s:16:"girlsignreg9.gif";
   }
  }
}
i:2;a:2:{
  s:4:"text"; s:1030:"<strong><span style="font-size:x-large;">BUSINESS SUCCESS IN 2008</span></strong><br> <br><span style="font-size:large;"><strong>Planning is the key to effective marketing - but it doesn't have to be complicated.</strong></span><br><br>Every small business owner wants to keep business coming in the door so that slow times are few and far between. That means creating a marketing and public relations plan of attack.<br><br><strong>How savvy are you when it comes to promoting your products and services?<br>Do you know who your target market is and where they are?<br>Do you have an annual marketing plan with timelines and budgets?</strong><br><br>If you haven't already, now is a perfect time to evaluate last year's marketing efforts and create a strategic marketing plan for this year. Be sure to remember that it doesn't have to be complicated to be effective and <span style="text-decoration:underline;"><strong>always keep in mind your target market.</strong></span>";
  s:8:"imageloc"; s:4:"left";
}
}
';

 

it seems that if html_entities doesnt change anything, it counts properly... but if it does... it still uses the old numbers...?

Link to comment
Share on other sites

might we be able to make new function(s)?

 

say... a function that print_r(); the variable, and returns the result (buffering to stop output)... that way we get a nice

 

array(

"key"=>"value"

);

 

only problem is how to turn that string, back into the array...?

Link to comment
Share on other sites

its because i'm saving it into the database, say the customer presses SAVE it'll put it into the database, then at any later time, they can come, and continue from it... like a drafts in an email...

 

 

usually your right... the builtin htmlentities() cannot, my html_entities() can ;)

Link to comment
Share on other sites

You're not showing us your complete code or what your html_entities() function is really doing. So, your html_entities() function must be returning an array. It must be doing htmlentities() on each value of the array, I guess. If that's all your function is doing, then you don't need a function and can just use array_walk().

 

You can always save as-is and do the htmlentities() after retrieving the data (just before outputing/displaying).

 

FYI: I would reorganize the database in the first place so I wouldn't have to save serialized info in the table.

 

Link to comment
Share on other sites

its quite a straightforward function...

 

<?
function html_entities($string){
if(!is_array($string)) return str_replace(array('&','"',"'",'<','>'), array('&','"',''','<','>'),$string);
foreach($string as $k=>$v) $string[$k]=html_entities($v);
return $string;
}
?>

 

and no, the database is just holding one instance of a "draft" at a time

 

the tables set up properly, that function works perfectly(i had it count the strings, its fine) the issue is within that serializer, its counting each of my text fields as longer then it truely is...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.