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
Solved

another PHP unserialize() function not working

Posted on 2009-05-07
15
279 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

829 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