PHP array characters, converting arrays
The following is the string after the output of the array. I want to convert it to an array.
Array (9) {
["productCode"] = + string (12) "1111"
["resourcecode"] = + string (13) "222"
["usercode"] = + string (9) "333"
["tvcode"] = + string (8) "444"
["extraInfo"] = + string (4) "NULL"
["orderresult"] = + string (1) "1"
["subId"] = + string (2) "1"
["payment"] = + string (1) "1"
["_url_"] + = Array (2) {
[0] = = string (3) "Test"
[1] = = string (+) "Callback"
}
}
Eval (' $dd = '. $result. '; ');
But has been an error. Sweat.
Share to:
------Solution--------------------
How did you get this string? It is output with var_dump, it is best to post all the code for analysis.
------Solution--------------------
$s =<<< TXT
Array (9) {
["productCode"] = + string (12) "1111"
["resourcecode"] = + string (13) "222"
["usercode"] = + string (9) "333"
["tvcode"] = + string (8) "444"
["extraInfo"] = + string (4) "NULL"
["orderresult"] = + string (1) "1"
["subId"] = + string (2) "1"
["payment"] = + string (1) "1"
["_url_"] + = Array (2) {
[0] = = string (3) "Test"
[1] = = string (+) "Callback"
}
}
TXT;
$s = Preg_replace_callback ('/(\[
------Solution--------------------
\]
------Solution--------------------
String
------Solution--------------------
\ (\d+\))
------Solution--------------------
({
------Solution--------------------
}
------Solution--------------------
"\s+)/', ' foo ', $s);
$ar = eval (' Return '. Trim ($s, ', '). ';');
Print_r ($ar);
function foo ($r) {
if ($r [1]) return ';
if ($r [2] = = ' {') return ' (';
if ($r [2] = = '} ') return '), ';
Return ' ", '. Php_eol;
}
Array
(
[ProductCode] = 1111
[Resourcecode] = 222
[Usercode] = 333
[Tvcode] = 444
[ExtraInfo] = null
[Orderresult] = 1
[SubId] = 1
[Payment] = 1
[_url_] = = Array
(
[0] = = Test
[1] = callback
)
)