seventeen
seventeen

Reputation: 443

PHP: Converting this data structure into an associative array

I have a field created by word press which contains data with the following structure.

a:16:{s:7:"country"
s:14:"United Kingdom"
s:7:"form_id"
s:2:"35"
s:9:"timestamp"
s:10:"1560869327"
s:7:"request"
s:0:""
s:8:"_wpnonce"
s:10:"125"
s:16:"_wp_http_referer"
s:1:"/"
s:17:"ajaxy-umajax-mode"
s:8:"register"
s:10:"first_name"
s:5:"xxxxx"
s:9:"last_name"
s:5:"xxx"
s:10:"user_email"
s:28:"[email protected]"
s:7:"Company"
s:16:"xxx LTD"
s:12:"phone_number"
s:10:"0123456789"
s:8:"user_url"
s:20:"http://www.test.com"
s:15:"company_address"
s:18:"999 LockSmith Lane"
s:12:"display_name"
s:12:"XXXX"
s:10:"user_login"
s:10:"xxx123"
}

I want to convert this to an array so I can read the properties of it.

I tried converting it to json but its not json.

Any ideas on how I can parse this data, or access its properties in PHP.

I can not access this data through wordpress as my PHP script is part of something else.

Upvotes: 0

Views: 70

Answers (2)

Shaniawan
Shaniawan

Reputation: 243

This is Actually not a json.This is an array in serialized format you can just unserilize it by using this function maybe_unserialize($YOUR_ARRAY). maybe_unserialize is a wordpress default function to unserialize the array

Upvotes: -1

Andrew
Andrew

Reputation: 825

Seems like a serialized array. Try unserializing it to convert it back to normal, see example.

Upvotes: 2

Related Questions