PHP几个函数兼容

  1. <?php
  2. if (! function_exists ( 'json_decode' )) {
  3.     
  4.     /**
  5.      * Decodes a JSON string
  6.      *
  7.      * @param string $content The jsonstring being decoded.
  8.      * @param bool $assoc When true, returned objects will be converted into associative arrays.
  9.      * @return mixed Returns an object or if the optional assoc parameter is true, an associative array is instead returned.
  10.      *
  11.      */
  12.     function json_decode($content$assoc = false) {
  13.         require_once '../Lib/Json/JSON.php';
  14.         if ($assoc) {
  15.             $json = new Services_JSON ( SERVICES_JSON_LOOSE_TYPE );
  16.         } else {
  17.             $json = new Services_JSON ( );
  18.         }
  19.         return $json->decode ( $content );
  20.     }
  21. }
  22. if (! function_exists ( 'json_encode' )) {
  23.     
  24.     /**
  25.      * Returns the JSON representation of a value
  26.      *
  27.      * @param mixed $content The value being encoded. Can be any type except a resource. This function only works with UTF-8 encoded data.
  28.      * @return string Returns a JSON encoded string on success.
  29.      *
  30.      */
  31.     function json_encode($content) {
  32.         require_once '../Lib/Json/JSON.php';
  33.         $json = new Services_JSON ( );
  34.         
  35.         return $json->encode ( $content );
  36.     }
  37. }
  38. if (! function_exists ( 'property_exists' )) {
  39.     
  40.     /**
  41.      * Checks if the object or class has a property
  42.      *
  43.      * @param mixed $class he class name or an object of the class to test for
  44.      * @param string $property The name of the property
  45.      * @return bool Returns true if the property exists, false if it doesn't exist or null in case of an error.
  46.      *
  47.      */
  48.     function property_exists($class$property) {
  49.         if (is_object ( $class )) {
  50.             $vars = get_object_vars ( $class );
  51.         } else {
  52.             $vars = get_class_vars ( $class );
  53.         }
  54.         return array_key_exists ( $property$vars );
  55.     }
  56. }
  57. if (! function_exists ( 'stripslashes_deep' )) {
  58.     
  59.     /**
  60.      * Un-quote string quoted with addslashes
  61.      *
  62.      * @param string $value The input string
  63.      * @return string Returns a string with backslashes stripped off. (/' becomes ' and so on.) Double backslashes (//) are made into a single backslash (/).
  64.      *
  65.      */
  66.     function stripslashes_deep($value) {
  67.         $value = is_array ( $value ) ? array_map ( 'stripslashes_deep'$value ) : stripslashes ( $value );
  68.         return $value;
  69.     }
  70. }
  71. ?>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值