You are here

function _search_autocomplete_json_encode in Search Autocomplete 7.3

Backwards-compatible JSON encoder.

Provides backwars-compatible support for more JSON encoding formats. Uses PHP's native JSON encoding when PHP 5.3.0 or greater is detected. Fallbacks to manual encoding/escaping when PHP 5.2.x and below is detected.

Parameters

array $rows: Results from template_preprocess_views_search_autocomplete_style_simple().

int $bitmask: Integer to use as the $bitmask parameter for json_encode().

1 call to _search_autocomplete_json_encode()
views-search-autocomplete-style.tpl.php in views/theme/views-search-autocomplete-style.tpl.php

File

./search_autocomplete.view_autocomplete.inc, line 345
Search Autocomplete Enables autocomplete functionality on search fields.

Code

function _search_autocomplete_json_encode($rows, $bitmask = NULL) {
  if (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3) {
    $json = json_encode($rows, $bitmask);

    // Encoding features not supported before 5.4.x.
    if (PHP_MINOR_VERSION <= 4) {
      $json = str_replace(array(
        '\\/',
      ), array(
        '/',
      ), $json);
    }
  }
  else {
    $json = json_encode($rows);
    $json = str_replace(array(
      '\\/',
    ), array(
      '/',
    ), $json);
  }
  return $json;
}