Php array character, which is the string output by the array. I want to convert it into an array (9) & nbsp ;{& nbsp; & nbsp; ["productCode"] & nbsp ;=& gt; & nbsp; string (12) & nbsp; "1111" & nbsp; ["resourceCode"] & n php array characters, conversion array
The following is the string output by the array. I want to convert it into an array
Array (9 ){
["ProductCode"] = & gt; string (12) "1111"
["ResourceCode"] => string (13) "222"
["UserCode"] = & gt; 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 (14) "callback"
}
}
Eval ('$ dd ='. $ result .';');
But always reports an error. Khan. Share :? String (12 )? "1111 "?? ["ResourceCode"... 'data-pics = ''>
------ Solution --------------------
How did you get this string. It is output with var_dump. it is best to paste all the code for analysis.
------ Solution --------------------
$ S = <TXT
Array (9 ){
["ProductCode"] = & gt; string (12) "1111"
["ResourceCode"] => string (13) "222"
["UserCode"] = & gt; 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 (14) "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
)
)