Skip to content

Instantly share code, notes, and snippets.

@sany2k8
Created July 28, 2017 16:36
Show Gist options
  • Select an option

  • Save sany2k8/5fee4a836d8a2e044709c36248dfbfe3 to your computer and use it in GitHub Desktop.

Select an option

Save sany2k8/5fee4a836d8a2e044709c36248dfbfe3 to your computer and use it in GitHub Desktop.
function escapeJsonString($value) {
# list from www.json.org: (\b backspace, \f formfeed)
$escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
$replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
$result = str_replace($escapers, $replacements, $value);
return $result;
}
$mongo = array('d','48na03af');
echo escapeJsonString(json_encode($ary));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment