Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use <a href="http://www.json.org" rel="nofollow">JSON</a> -- it's serialized Javascript Object Notation and is pretty close to what you're doing.</p> <p>You'd need to do</p> <pre><code>var MyAssocArray = JSON.parse(MyString); </code></pre> <p>Also, JSON uses double quotes, not single quotes; if you use simple objects you can probably write code to just replace <code>'</code> with <code>"</code>" in your strings, but it's tricky if the strings contain double-quotes.</p> <p>edit: If you are using a browser that doesn't implement JSON.parse(), you can either use the implementation on the JSON website (see <a href="http://www.json.org/js.html" rel="nofollow">links at bottom of this page</a>) or if you're using jQuery, there's <a href="http://api.jquery.com/jQuery.parseJSON/" rel="nofollow">jQuery.parseJSON()</a></p> <hr> <p>Edit#2: <strong>Warning</strong>: Your solution has a security risk, unless you are sure the data in the database has been sanitized:</p> <pre><code> var My_Single_Dime_Arr = {&lt;?php echo $String_Pulled_From_Database; ?&gt;} </code></pre> <p>This is equivalent to a call to <code>eval()</code>; if your database string has any malicious code it can do bad things. This is one reason why JSON was invented -- it's easy to ensure that its contents are valid (and hence safe) before evaluated.</p> <p>Your overall architecture, as you have presented it to us, is [data in database] -> server-side PHP -> client-side Javascript. This is a classic example of serialized data. I realize you may have constraints to keep your system running without interruption, but a strict serialization format would make your system more secure.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload