PHP: How to unserialize for XML string

WordPress is a powerfull tool for blog and it keep all data  in serialize format and user can easily get these values from database by get_option() function. But some time we need to use unserialize function to get some specific value from the string. So we simply use unserialize function on stored string and get value.

WordPress provides many type of widgets and some widgets provide interaction with social networks like linkedin, facebook, etc. and wordpress store its related value as :


array('O:16:"SimpleXMLElement":0:{}', 'O:16:"SimpleXMLElement":')

When user use unserialize function to get this string then he gets error for unserialize function.

So for this you can unserialize  the string by following code:


$linkedinData = unserialize ( str_replace ( array('O:16:"SimpleXMLElement":0:{}', 'O:16:"SimpleXMLElement":'),  array('s:0:"";', 'O:8:"stdClass":'), $linkedinData));

When you print this $linkedinData array you will see that your string has been converted into an array.


Comments

3 responses to “PHP: How to unserialize for XML string”

Leave a Reply

Your email address will not be published. Required fields are marked *

*