This question already has an answer here:
I am having trouble get multiple substring from a string using PHP
For example:
$id= 'a:4:{i:0;s:4:"8345";i:1;s:4:"8344";i:2;s:4:"8343";i:3;s:4:"8329";}';
Now I want get the results as:
Array[0]=> 8345
Array[1]=> 8344
Array[2]=> 8343
Array[3]=> 8329
Any suggestions?
</div>
unserialize() takes a single serialized variable and converts it back into a PHP value
$id= 'a:4:{i:0;s:4:"8345";i:1;s:4:"8344";i:2;s:4:"8343";i:3;s:4:"8329";}';
print_r(unserialize($id));
Just unserialize the data
<?php
$id= unserialize('a:4:{i:0;s:4:"8345";i:1;s:4:"8344";i:2;s:4:"8343";i:3;s:4:"8329";}');
print_r($id);
?>
$returnValue = unserialize($id);
the result will be like
array (
0 => '8345',
1 => '8344',
2 => '8343',
3 => '8329',
)
Regex:
$id= 'a:4:{i:0;s:4:"8345";i:1;s:4:"8344";i:2;s:4:"8343";i:3;s:4:"8329";}';
preg_match_all("/\d{4}/", $id, $numbers);
var_dump($numbers);
Matches all four digit numbers.