Files
youlegames/codes/agent/game/api/framework/function/compat.func.php
2026-03-15 01:27:05 +08:00

78 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
defined('IN_IA') or exit('Access Denied');
if (!function_exists('json_encode')) {
function json_encode($value) {
static $jsonobj;
if (!isset($jsonobj)) {
include_once (IA_ROOT . '/framework/library/json/JSON.php');
$jsonobj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
}
return $jsonobj->encode($value);
}
}
if (!function_exists('json_decode')) {
// 将传入的字符串解码为一个json字符串
function json_decode($jsonString) {
// decode解码为一个JSON字符串
static $jsonobj;
if (!isset($jsonobj)) {
include_once (IA_ROOT . '/framework/library/json/JSON.php');
$jsonobj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
}
return $jsonobj->decode($jsonString);
}
}
if (!function_exists('http_build_query')) {
// 构建http请求参数
function http_build_query($formdata, $numeric_prefix = null, $arg_separator = null) {
// 假如参数不是数组的话则直接返回false
if (!is_array($formdata))
return false;
// 假如没有设置参数分割符,则默认设置为&
if ($arg_separator == null)
$arg_separator = '&';
return http_build_recursive($formdata, $arg_separator);
}
// 采用递归的方式拼接参数为字符串
// 参数1要拼接的参数数组
// 参数2要拼接使用的参数分割符
function http_build_recursive($formdata, $separator, $key = '', $prefix = '') {
$rlt = '';
foreach ($formdata as $k => $v) {
if (is_array($v)) {
if ($key)
$rlt .= http_build_recursive($v, $separator, $key . '[' . $k . ']', $prefix);
else
$rlt .= http_build_recursive($v, $separator, $k, $prefix);
} else {
if ($key)
$rlt .= $prefix . $key . '[' . urlencode($k) . ']=' . urldecode($v) . '&';
else
$rlt .= $prefix . urldecode($k) . '=' . urldecode($v) . '&';
}
}
return $rlt;
}
}
if (!function_exists('file_put_contents')) {
function file_put_contents($file, $string) {
$fp = @fopen($file, 'w') or exit("Can not open $file");
flock($fp, LOCK_EX);
$stringlen = @fwrite($fp, $string);
flock($fp, LOCK_UN);
@fclose($fp);
return $stringlen;
}
}
if (!function_exists('getimagesizefromstring')) {
function getimagesizefromstring($string_data) {
$uri = 'data://application/octet-stream;base64,' . base64_encode($string_data);
return getimagesize($uri);
}
}