1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Common;
- trait DecodeTrait
- {
- public static function decodeBoxNo($arr = [])
- {
- $str = '';
- foreach ($arr as $item) {
- $str .= (int)$item;
- }
- return $str;
- }
- public static function decodeLocation($arr = [])
- {
- $str = '';
- foreach ($arr as $key => $item) {
- $str .= hexdec($item);
- if ($key === 0) {
- $str .= '.';
- }
- }
- return $str;
- }
- /**
- * 截取响应的数据串
- * @param $arr
- * @param $offset
- * @param bool $length
- * @return
- * Author: Mead
- */
- public static function stitching($arr, $offset, $length = false, $is_string = true)
- {
- $body = [];
- if ($length === false) {
- $body = array_slice($arr, $offset);
- } else {
- $body = array_slice($arr, $offset, $length);
- }
- if (!$is_string) return $body;
- return implode('', $body);
- }
- }
|