Attempt to fix paging on contact summary
[civicrm-core.git] / CRM / Utils / JSON.php
index 6aa8af5de2093df20b7e7e34ab1b7e299a49b970..7ec004714fe3fe1d56f392006509254b66ede7e2 100644 (file)
@@ -46,6 +46,16 @@ class CRM_Utils_JSON {
     CRM_Utils_System::civiExit();
   }
 
+  /**
+   * Test whether the input string is valid JSON.
+   * @param string $str
+   * @return boolean
+   */
+  public static function isValidJSON($str) {
+    json_decode($str);
+    return json_last_error() == JSON_ERROR_NONE;
+  }
+
   /**
    * Do not use this function. See CRM-16353.
    * @deprecated
@@ -78,7 +88,7 @@ class CRM_Utils_JSON {
         // CRM-7130 --lets addslashes to only double quotes,
         // since we are using it to quote the field value.
         // str_replace helps to provide a break for new-line
-        $sOutput .= '"' . addcslashes(str_replace(array("\r\n", "\n", "\r"), '<br />', $value[$element]), '"\\') . '"';
+        $sOutput .= '"' . addcslashes(str_replace(["\r\n", "\n", "\r"], '<br />', $value[$element]), '"\\') . '"';
 
         // remove extra spaces and tab character that breaks dataTable CRM-12551
         $sOutput = preg_replace("/\s+/", " ", $sOutput);