taith Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/ Share on other sites More sharing options...
dave420 Posted February 20, 2008 Share Posted February 20, 2008 That's because the bit of HTML is 59 characters long, not 51. Maybe it has something to do with the HTML entities in there (as if they replaced the quotes, that would account for the extra 8 characters)? Link to comment https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471839 Share on other sites More sharing options...
toplay Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471864 Share on other sites More sharing options...
dave420 Posted February 20, 2008 Share Posted February 20, 2008 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. Link to comment https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471870 Share on other sites More sharing options...
taith Posted February 20, 2008 Author Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471871 Share on other sites More sharing options...
taith Posted February 20, 2008 Author Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471874 Share on other sites More sharing options...
dave420 Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471882 Share on other sites More sharing options...
taith Posted February 20, 2008 Author Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471887 Share on other sites More sharing options...
toplay Posted February 20, 2008 Share Posted February 20, 2008 Did you try setting it to temporary var first....i.e. $temail = html_entities($_SESSION); $temail = serialize($temail]); Link to comment https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471928 Share on other sites More sharing options...
taith Posted February 20, 2008 Author Share Posted February 20, 2008 yes... same issue... for what i can tell the # s:4:"text"; s:[b]953[/b]:"<span style="......."; is always 2 higher then it should be... as in... it should be 951 Link to comment https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-471990 Share on other sites More sharing options...
taith Posted February 20, 2008 Author Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-472001 Share on other sites More sharing options...
toplay Posted February 20, 2008 Share Posted February 20, 2008 1) Since you're using sessions, I don't understand why you're bothering to serialize anything. Just save the array as-is to the session variable. 2) If your $_SESSION is an array, then you can't pass that as an argument to html_entities() because it's expecting a string. Link to comment https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-472016 Share on other sites More sharing options...
taith Posted February 20, 2008 Author Share Posted February 20, 2008 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... 2) If your $_SESSION is an array, then you can't pass that as an argument to html_entities() because it's expecting a string. usually your right... the builtin htmlentities() cannot, my html_entities() can Link to comment https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-472020 Share on other sites More sharing options...
toplay Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-472034 Share on other sites More sharing options...
taith Posted February 20, 2008 Author Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/92135-unserialize-issues/#findComment-472045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.