XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
functions.encoding.php
Go to the documentation of this file.
1 <?php
5 /*
6  You may not change or alter any portion of this comment or credits
7  of supporting developers from this source code or any supporting source code
8  which is considered copyrighted (c) material of the original comment or credit authors.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  */
14 
25 defined('XOOPS_ROOT_PATH') or die('Restricted access');
26 
33 function xoops_hex2bin($hex)
34 {
35  if (!is_string($hex)) return null;
36  $r = '';
37  $len = strlen($hex);
38  for ($a = 0; $a < $len; $a += 2) {
39  $r .= chr(hexdec($hex{$a} . $hex{($a + 1)}));
40  }
41  return $r;
42 }
43 
50 function xoops_bin2hex($bin)
51 {
52  return bin2hex($bin);
53 }
54 
62 function xoops_ishexstr($hex, $checklen = 32)
63 {
64  $accepted = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
65  $len = strlen($hex);
66  if ($checklen > $len) {
67  $checklen = $len;//And???
68  }
69  $hex = strtolower($hex);
70  for ($i = 0; $i < $len; $i++) {
71  if (!in_array($hex{$i}, $accepted)) {
72  return false;
73  }
74  }
75  return true;
76 }
77 
85 function xoops_convert_encode($data, $store_method = "urlcode") {
86  switch ($store_method) {
87  default:
88  return urlencode($data);
89  case "base64":
90  return base64_encode($data);
91  case "uucode":
92  return convert_uuencode($data);
93  case "open":
94  return $data;
95  case "hex":
96  return bin2hex($data);
97  }
98 }
99 
107 function xoops_convert_decode($data, $store_method = "urlcode") {
108  switch ($store_method) {
109  default:
110  return urldecode($data);
111  case "base64":
112  return base64_decode($data);
113  case "uucode":
114  return convert_uudecode($data);
115  case "open":
116  return $data;
117  case "hex":
118  return xoops_hex2bin($data);
119  }
120 }
121 
129 function xoops_aw_encode($value, $key, $store_method = "urlcode") {
130  $value = xoops_convert_encode($value, $store_method);
131 }
132 
140 function xoops_aw_decode($value, $key, $store_method = "urlcode") {
141  $value = xoops_convert_decode($value, $store_method);
142 }
143 
144 ?>