I have to fetch the wp-options table from the wordpress database and i have to unserialise the serialise data. my code for get the option values from the database table is written bellow.
function option_value_change () {
global $wpdb;
$myrows = $wpdb->get_results( "SELECT *
FROM `wp_options`");
foreach ($myrows as $rows){
$option = get_option($rows->option_name);
modify_domain_name($option);
echo $rows-> option_value ."<br />";
}
}
Now i want to check the serialise data. How can i check the data as serialise data.If that is a serialise data then how can i unserialise that data.
Maybe check if it is an object, or an array, and if not, then unserialize it.
<?php
if (!is_array($var) && !is_object($var)) {
$var = unserialize($var);
}
?>
Or, depending on if your data is positively going to either be an object/array, or serialized data, you could also just test if it is a string.
<?php
if (is_string($var)) {
$var = unserialize($var);
}
?>
Wordpress has a function called maybe_unserialize() that will fit your job.
As its name suggest, the function will unserialize a variable only if it is serialized.
EDIT:
I don't know your current needs, but just in case you didn't know, WordPress has a get_option() function which reads a value form the options
table and unserialize it if needed before returning it to you.