Solved

another PHP unserialize() function not working

Posted on 2009-05-07
15
274 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now