Solved

another PHP unserialize() function not working

Posted on 2009-05-07
15
278 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php convert date format 3 21
Download tables into separate sheets 3 27
Decrypt string by php 7 31
What does this formatting equate to? 7 10
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 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