-3

I am saving data in database in serialize format but when i unserialize it does not return array. Here is the example data of serailize. Can anyone please guide me what is wrong in it.

a:5:{s:3:"upc";a:30:{i:0;s:0:"";i:3;s:0:"";i:4;s:0:"";i:5;s:0:"";i:6;s:0:"";i:7;s:0:"";i:8;s:0:"";i:9;s:0:"";i:10;s:0:"";i:11;s:0:"";i:12;s:0:"";i:13;s:0:"";i:14;s:0:"";i:15;s:0:"";i:16;s:0:"";i:17;s:0:"";i:18;s:0:"";i:19;s:0:"";i:21;s:0:"";i:23;s:0:"";i:27;s:0:"";i:28;s:0:"";i:29;s:0:"";i:30;s:0:"";i:31;s:0:"";i:32;s:0:"";i:33;s:0:"";i:35;s:0:"";i:36;s:0:"";i:37;s:0:"";}s:5:"brand";a:30:{i:0;s:13:"Artisan Farms";i:3;s:13:"Artisan Farms";i:4;s:13:"Artisan Farms";i:5;s:8:"Thornloe";i:6;s:8:"Thornloe";i:7;s:18:"Nutri Spring Farms";i:8;s:18:"Nutri Spring Farms";i:9;s:9:"Top Grass";i:10;s:9:"Top Grass";i:11;s:19:"L\'Ancetre. Non-GMO";i:12;s:19:"L\'Ancetre. Non-GMO";i:13;s:38:"Bob\'s Red Mill. Gluten-Free. Kosher. ";i:14;s:7:"CanPrev";i:15;s:7:"CanPrev";i:16;s:19:"Natural Traditions ";i:17;s:18:"Natural Traditions";i:18;s:28:"PUR 100% Xylitol Chewing Gum";i:19;s:9:"New Roots";i:21;s:22:"Yorkshire Valley Farms";i:23;s:14:"Rolling Meadow";i:27;s:38:"Any farm raised chicken eggs available";i:28;s:24:"VG Meats - Four Brothers";i:29;s:22:"Yorkshire Valley Farms";i:30;s:17:"Pure-l? Natural ";i:31;s:37:"Mangiatorella Italian Sparkling Water";i:32;s:37:"Mangiatorella Italian Sparkling Water";i:33;s:37:"Mangiatorella Italian Sparkling Water";i:35;s:38:"AOR - Advanced Orthomolecular Research";i:36;s:22:"Stahlbush Island Farms";i:37;s:16:"Navitas Organics";}s:4:"size";a:30:{i:0;s:5:"452 g";i:3;s:5:"452 g";i:4;s:5:"452 g";i:5;s:5:"250 g";i:6;s:5:"250 g";i:7;s:41:"Medium Preferably - Or whatever available";i:8;s:41:"Medium Preferably - Or whatever available";i:9;s:11:"Around 1 lb";i:10;s:11:"Around 1 lb";i:11;s:5:"150 g";i:12;s:6:"150 gm";i:13;s:5:"453 g";i:14;s:11:"60 Capsules";i:15;s:7:"60 Caps";i:16;s:11:"90 Capsules";i:17;s:11:"90 Capsules";i:18;s:8:"55 Count";i:19;s:10:"60 Capules";i:21;s:19:"Medium size package";i:23;s:5:"500 g";i:27;s:9:"12 Counts";i:28;s:22:"Medium Around 3 pounds";i:29;s:20:"Medium sized package";i:30;s:7:"0.12 lb";i:31;s:6:"750 ml";i:32;s:6:"750 ml";i:33;s:6:"750 ml";i:35;s:5:"450 g";i:36;s:5:"300 g";i:37;s:5:"227 g";}s:16:"item_description";a:30:{i:0;s:25:"Frozen Grass-fed Burgers ";i:3;s:24:"Frozen Grass-fed Burgers";i:4;s:24:"Frozen Grass-fed Burgers";i:5;s:26:"Grass-fed unsalted butter ";i:6;s:26:"Grass-fed unsalted butter ";i:7;s:33:"Frozen ABF Free-run Turkey Fillet";i:8;s:33:"Frozen ABF Free-run Turkey Fillet";i:9;s:24:"Frozen Lean Ground Beef ";i:10;s:24:"Frozen Lean Ground Beef ";i:11;s:25:"Organic Greek Feta Cheese";i:12;s:25:"Organic Greek Feta Cheese";i:13;s:21:"Organic Coconut Flour";i:14;s:37:"Synergy B - B complex with L-Theanine";i:15;s:37:"Synergy B - B complex with L-Theanine";i:16;s:18:"Camu C - Vitamin C";i:17;s:18:"Camu C - Vitamin C";i:18;s:38:"Coolmint Flavour (light green package)";i:19;s:65:"Reishi - Energy & Stress 40% Polysaccharides Hot-Water Extraction";i:21;s:67:"Organic Chicken Tenders OR if not available Boneless Chicken Breast";i:23;s:29:"Plain Grass Fed Yoghurt 3.25%";i:27;s:56:"Hormone and Antibiotic Free, Cage-free and Free-run eggs";i:28;s:24:"Hormone Free Beef Tongue";i:29;s:67:"Organic Chicken Tenders OR if not available Boneless Chicken Breast";i:30;s:25:"Stevia liquid Concentrate";i:31;s:24:"Natural Sparkling Water ";i:32;s:24:"Natural Sparkling Water ";i:33;s:24:"Natural Sparkling Water ";i:35;s:18:"L-Glutamine Powder";i:36;s:34:"Frozen Organic Whole Strawberries ";i:37;s:21:"Organic Cacao Powder ";}s:3:"qty";a:30:{i:0;s:1:"0";i:3;s:0:"";i:4;s:0:"";i:5;s:0:"";i:6;s:0:"";i:7;s:0:"";i:8;s:0:"";i:9;s:0:"";i:10;s:0:"";i:11;s:0:"";i:12;s:0:"";i:13;s:0:"";i:14;s:0:"";i:15;s:0:"";i:16;s:0:"";i:17;s:0:"";i:18;s:0:"";i:19;s:0:"";i:21;s:0:"";i:23;s:0:"";i:27;s:0:"";i:28;s:0:"";i:29;s:0:"";i:30;s:0:"";i:31;s:0:"";i:32;s:0:"";i:33;s:0:"";i:35;s:0:"";i:36;s:0:"";i:37;s:0:"";}}
stackers
  • 385
  • 4
  • 18
  • Please don't just ask us to solve the problem for you. Show us how you tried to solve the problem yourself, then show us exactly what the result was, and tell us why you feel it didn't work. Give us a **clear explanation of what isn't working** and provide [a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Read [How to Ask](http://stackoverflow.com/help/how-to-ask) a good question. Be sure to [take the tour](http://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/q/347937/1011527). – Jay Blanchard May 05 '20 at 19:51
  • It's really hard to troubleshoot where a serialized string has gone wrong. This is why json is preferable. – aynber May 05 '20 at 20:01
  • Serlialization uses backslash characters for escaping, and so do some databases. Make sure you use a prepared statement with parameters when storing serialized data, or at least escape the data. – Barmar May 05 '20 at 20:05

1 Answers1

0

Trying to unserialize that string throws:

Notice: unserialize(): Error at offset 1097 of 3784 bytes in ...

At offset 1097, is the end of s:17:"Pure-l? Natural ".
At closer inspection it reveals, that that string has only 16 characters, instead of the expected 17.
? is usually the character that is used for characters that can't be reencoded. It seems some 2 byte character was replaced with a one byte one.

Make sure your database can handle UTF-8 encoded strings.
Please check "UTF-8 all the way through" for help with that.

gre_gor
  • 6,669
  • 9
  • 47
  • 52