Solved

another PHP unserialize() function not working

Posted on 2009-05-07
15
282 Views
Last Modified: 2013-12-13
I am working with php code ... I saw this special function called unserialize() which converting a formated string into array form. But now it is not working ...

$data= "a:5: {i:0;s:6:"entire";i:1;s:6:"hourly";i:2;s:5:"daily";i:3;s:6:"weekly";i:4; s:7:"monthly";}";
$dat = unserialize($data);
if (is_array($dat))
{
  I got nothing!!!!
   foreach ($dat as $key => $value)
   {
     I got nothing!!!!
   }
}

The above code... is there anything wrong??
0
Comment
Question by:cwteoh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24323533
Hi.,

Use the following:

Its working fine.

Regards
$data='a:5:{i:0;s:6:"entire";i:1;s:6:"hourly";i:2;s:5:"daily";i:3;s:6:"weekly";i:4;s:7:"monthly";}';
$dat = unserialize($data);
if (is_array($dat))
{
  I got nothing!!!!
   foreach ($dat as $key => $value)
   {
     I got nothing!!!!
   }
}

Open in new window

0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24323542
Soryy,

use :

$data='a:5:{i:0;s:6:"entire";i:1;s:6:"hourly";i:2;s:5:"daily";i:3;s:6:"weekly";i:4;s:7:"monthly";}';
$dat = unserialize($data);
if (is_array($dat))
{
  echo "I got nothing!!!!";
   foreach ($dat as $key => $value)
   {
     echo "I got nothing!!!!";
   }
}



I missed echo.

0
 
LVL 1

Author Comment

by:cwteoh
ID: 24323810
sorry...

"I got nothing" - is my remark... mean I did not get anything from the array
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:shobinsun
ID: 24323835
Hi,

check  print_r($dat);
0
 
LVL 1

Author Comment

by:cwteoh
ID: 24323857
$data= "a:5: {i:0;s:6:"entire";i:1;s:6:"hourly";i:2;s:5:"daily";i:3;s:6:"weekly";i:4; s:7:"monthly";}";
$dat = unserialize($data);

why is the $dat contains no data?

I tried print_r($dat); but no output?

0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24323872
Hi,

I got array with values by the following code:

o/p:

Array ( [0] => entire [1] => hourly [2] => daily [3] => weekly [4] => monthly )

code:

$data='a:5:{i:0;s:6:"entire";i:1;s:6:"hourly";i:2;s:5:"daily";i:3;s:6:"weekly";i:4;s:7:"monthly";}';
$dat = unserialize($data);
if (is_array($dat))
{
  echo "I got nothing!!!!";
   foreach ($dat as $key => $value)
   {
     echo "I got nothing!!!!";
   }
}
print_r($dat);
0
 
LVL 1

Author Comment

by:cwteoh
ID: 24332563
well, i didn't got anything from the output...any clue?
0
 
LVL 1

Author Comment

by:cwteoh
ID: 24332987
I believe count($dat) should return the quantity of array to me... and the turn is 1.
0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24333069
Hi,

count($dat) will return the exact count in the array.

And please try this:

var_dump($dat);

And also please set the php.ini for getting warnings and notices.

error_reporting  =  E_ALL


Hope this will help you.

Regards.
0
 
LVL 1

Author Comment

by:cwteoh
ID: 24333500
what is var_dump($dat); for?

Where to find php.ini. I don'think I got 1
0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24333532
Hi,

var_dump  Dumps information about a variable.

This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.

Look at the php folder in your machine for php.ini (Look at the php installation folder. May be c:/windows or c:\xampp/php  if you are using xampp).


And what output you get with var_dump() ?

Hope this will help you.

0
 
LVL 1

Author Comment

by:cwteoh
ID: 24393593
nothing is shown...
0
 
LVL 14

Expert Comment

by:shobinsun
ID: 24393835
Hi,

Any errors or warnings or Notices?

0
 
LVL 1

Author Comment

by:cwteoh
ID: 24408848
no...
0
 
LVL 14

Accepted Solution

by:
shobinsun earned 125 total points
ID: 24438774
Hi,

Look at the php folder in your machine for php.ini (Look at the php installation folder->c:\xampp\php\php.ini  if you are using xampp).

And do :

set the php.ini for getting warnings and notices.

error_reporting  =  E_ALL


And try again. You will get atleast one notice.

Hope this will give you the error.

And please give me the feedback.

Regards
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question