You are here

function globallink_escape_json_string in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.7 globallink.inc \globallink_escape_json_string()
  2. 7.5 globallink.inc \globallink_escape_json_string()

Escapes JSON string.

Parameters

string $value: The JSON string to be escaped.

Return value

string The escaped JSON string.

File

./globallink.inc, line 621
Miscellaneous GlobalLink functions for node translations (non-entity).

Code

function globallink_escape_json_string($value) {

  // list from www.json.org: (\b backspace, \f formfeed)
  $escapers = array(
    "\\",
    "/",
    "\"",
    "\n",
    "\r",
    "\t",
    "\10",
    "\f",
  );
  $replacements = array(
    "\\\\",
    "\\/",
    "\\\"",
    "\\n",
    "\\r",
    "\\t",
    "\\f",
    "\\b",
  );
  $result = str_replace($escapers, $replacements, $value);
  return $result;
}