w3resource

php.js : unserialize() function

unserialize() function

The unserialize() converts serialized data to actual data.

Version:

1103.1210

Syntax:

unserialize(string1)

Parameters:

Name Description

Example of php.js unserialize() function:

In the following web document, unserialize() function converts a serialize data to actual format.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>php.js : unserialize() function example</title>
<script type="text/javascript" src="../../phpjs/variable/variable.min.js"> </script>
</head>
<body>
<h1 style="color: green">php.js : unserialize() function example</h1>
<h3>Unserialize the serialized data...</h3>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
document.write('Original Array : '+" Array('Math', 'Language', 'Science')"+'<br />')
x=serialize(Array('Math', 'Language', 'Science'));
document.write("Serialized the above data ; " +'<br />');
var_dump(x);
y=unserialize(x);
document.write('<br />'+"Unserialize the above data and go back to original array : " +'<br />');
var_dump(y);
//]]>
</script>
</body>
</html>

Output of the function:

Original Array :  Array('Math', 'Language', 'Science')
Serialized the above data ; 
string(58) "a:3:{i:0;s:4:"Math";i:1;s:8:"Language";i:2;s:7:"Science";}"
Unserialize the above data and go back to original array :
array(3) {  [0] => string(4) "Math" [1] => string(8) "Language" [2] => string(7) "Science"  } 

View example of php.js unserialize() function in browser

Download phpjs.zip

Previous: php.js : strval() function
Next: php.js : var_dump() function



Share this Tutorial / Exercise on : Facebook and Twitter