Solved

another PHP unserialize() function not working

Posted on 2009-05-07
15
281 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
Independent Software Vendors: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

749 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