title: PHP/MYSQL/JSON: Parse complicated string or reassemble as dictionary
body: <p>I receive a complicate string through JSON that represents an object:</p>
  
  <pre><code>    &lt;Offers: 0x170483070&gt; (entity: Offers; id: 0xd00000000b880006 &lt;x-
  coredata://03C4A684-2218-489C-9EF6-42634ED10552/Offers/p738&gt; ; data: {\\n    
  topic = nil;\\n    topid = 9403;\\n    hasserverid = nil;\\n    isprivate = nil;\\n 
     lasttouched = \\\"2018-07-08 16:49:01 +0000\\\";\\n    lastviewed = nil;\\n
      localid = 42;\\n    needpicsync = nil;\\n    needsync = nil;\\n    secondorder
   = 0;\\n    oid = 0;\\n    offer = test;\\n    offerdone = nil;\\n    offernumber =
   70;\\n    userid = 1;\\n    wasdeleted = nil;\\n    whenadded = \\\"2018-07-08
   16:04:20 +0000\\\”;\\n})
  </code></pre>
  
  <p>I would like to save certain things to MYSQL.  In the above example, I would like to save the fields offer and offernumber among others to a record with something like:</p>
  
  <pre><code>$sql = "INSERT into offers (offer,offernumber) VALUES ('test',70)";
  </code></pre>
  
  <p>To do this, of course, I first have to parse the string to get the value for offer, the one for offer number and ideally, the keys and values for the entire object.</p>
  
  <p>Should I first convert the string into some sort of array,dictionary or data structure?  Or should I try to parse the string using regex or some other method?  If the latter, would appreciate suggestions on what what regex or technique to use.</p>
  
  <p>Thanks in advance for any suggestions!</p>