PHP string to array

后端 未结 4 821
北荒
北荒 2021-01-25 11:45

I have a string that when I var_dump returns the following

string(20) \"{\\\"key1\\\":\\\"key1_value\",\\\"key2\\\":\\\"key2_value\\\"}\"

How c

相关标签:
4条回答
  • 2021-01-25 12:15

    The explode function will get you what you need.

    0 讨论(0)
  • 2021-01-25 12:25
    explode(',\\',$string); 
    

    should do the trick.

    0 讨论(0)
  • 2021-01-25 12:40

    It looks like a simple JSON array that got mangled by PHP's magic_quotes or some other escaping function. Turn off magic_quotes and run json_decode() on the string.

    // If you cannot disable `magic_quotes` or you escaped it manually, use this
    $array = json_decode(stripslashes($strings), true);
    
    0 讨论(0)
  • 2021-01-25 12:41

    What you have as data looks like valid JSON. You probably can use json_decode with the second parameter to true (to get an associative array) like this:

    $array = json_decode($string, true);
    
    0 讨论(0)
提交回复
热议问题