Advertisement
Guest User

Untitled

a guest
Sep 11th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. require_once("../config/config.php");
  2. $arrayToJs = array();
  3. $arrayToJs[0] = $validateId;
  4. $arrayToJs[1] = $validateError;
  5. $isValidate = true;
  6.  
  7. if($isValidate == true)
  8. {
  9. echo "true";
  10. }
  11. else
  12. {
  13. $isValidate = false;
  14.  
  15. if (!function_exists('json_encode'))
  16. {
  17. function json_encode($a=false)
  18. {
  19. if (is_null($a)) return 'null';
  20. if ($a === false) return 'false';
  21. if ($a === true) return 'true';
  22. if (is_scalar($a))
  23. {
  24. if (is_float($a))
  25. {
  26. // Always use "." for floats.
  27. return floatval(str_replace(",", ".", strval($a)));
  28. }
  29.  
  30. if (is_string($a))
  31. {
  32. static $jsonReplaces = array(array("\", "/", "n", "t", "r", "b", "f", '"'), array('\\', '\/', '\n', '\t', '\r', '\b', '\f', '"'));
  33. return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
  34. }
  35. else
  36. return $a;
  37. }
  38.  
  39. $isList = true;
  40.  
  41. for ($i = 0, reset($a); $i < count($a); $i++, next($a))
  42. {
  43. if (key($a) !== $i)
  44. {
  45. $isList = false;
  46. break;
  47. }
  48. }
  49.  
  50. $result = array();
  51.  
  52. if ($isList)
  53. {
  54. foreach ($a as $v) $result[] = json_encode($v);
  55. return '[' . join(',', $result) . ']';
  56. }
  57. else
  58. {
  59. foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
  60. return '{' . join(',', $result) . '}';
  61. }
  62. }
  63. }
  64.  
  65. echo'{"jsonValidateReturn":'.json_encode($arrayToJs).'}';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement