-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUtil.php
executable file
·71 lines (57 loc) · 1.88 KB
/
Util.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require_once("Common.php");
class ArrayUtil {
public static function to_array($content, $response_type) {
if ($response_type == ResponseType::$JSON) {
return json_decode($content);
} else if ($response_type == ResponseType::$XML) {
$xml = @simplexml_load_string($content);
return self::xml_to_array($xml);
}
throw new Exception('ResponseType : ' . $response_type . ' Not Supported.');
}
public static function xml_to_array($xml) {
$arr = array();
if ($xml) {
foreach ($xml as $key => $value) {
if ($xml['count']) {
$arr[] = self::xml_to_array($value);
} else {
$arr[$key] = self::xml_to_array($value);
}
}
}
if (sizeof($arr) > 0) {
return $arr;
} else {
return (string)$xml;
}
}
}
class HttpUtil {
public static function get_server($uri) {
//TODO: do something better
$uri = preg_replace('/http(s)?:\/\//', '', strtolower($uri));
return $uri;
}
public static function get_protocol_port($uri) {
//TODO: do something better
if (substr($uri, 0, 5) == 'https') {
return 443;
} else if (substr($uri, 0, 4) == 'http') {
return 80;
}
return 80;
}
public static function convert_post_data($arr) {
$post_result = "";
foreach ($arr as $key => $value) {
$post_result .= $key . '=' . $value . '&';
}
if (strlen($post_result) > 0) {
$post_result = substr($post_result, 0, strlen($post_result)-1);
}
return $post_result;
}
}
?>