当前位置: 首页>>代码示例>>PHP>>正文


PHP unpack函数代码示例

本文整理汇总了PHP中unpack函数的典型用法代码示例。如果您正苦于以下问题:PHP unpack函数的具体用法?PHP unpack怎么用?PHP unpack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了unpack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: convert_uudecode

 function convert_uudecode($string)
 {
     // Sanity check
     if (!is_scalar($string)) {
         user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
         return false;
     }
     if (strlen($string) < 8) {
         user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING);
         return false;
     }
     $decoded = '';
     foreach (explode("\n", $string) as $line) {
         $c = count($bytes = unpack('c*', substr(trim($line), 1)));
         while ($c % 4) {
             $bytes[++$c] = 0;
         }
         foreach (array_chunk($bytes, 4) as $b) {
             $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20;
             $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20;
             $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20;
             $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20;
             $b0 <<= 2;
             $b0 |= $b1 >> 4 & 0x3;
             $b1 <<= 4;
             $b1 |= $b2 >> 2 & 0xf;
             $b2 <<= 6;
             $b2 |= $b3 & 0x3f;
             $decoded .= pack('c*', $b0, $b1, $b2);
         }
     }
     return rtrim($decoded, "");
 }
开发者ID:poppen,项目名称:p2,代码行数:33,代码来源:convert_uudecode.php

示例2: webid_claim

function webid_claim()
{
    $r = array('uri' => array());
    if (isset($_SERVER['SSL_CLIENT_CERT'])) {
        $pem = $_SERVER['SSL_CLIENT_CERT'];
        if ($pem) {
            $x509 = openssl_x509_read($pem);
            $pubKey = openssl_pkey_get_public($x509);
            $keyData = openssl_pkey_get_details($pubKey);
            if (isset($keyData['rsa'])) {
                if (isset($keyData['rsa']['n'])) {
                    $r['m'] = strtolower(array_pop(unpack("H*", $keyData['rsa']['n'])));
                }
                if (isset($keyData['rsa']['e'])) {
                    $r['e'] = hexdec(array_shift(unpack("H*", $keyData['rsa']['e'])));
                }
            }
            $d = openssl_x509_parse($x509);
            if (isset($d['extensions']) && isset($d['extensions']['subjectAltName'])) {
                foreach (explode(', ', $d['extensions']['subjectAltName']) as $elt) {
                    if (substr($elt, 0, 4) == 'URI:') {
                        $r['uri'][] = substr($elt, 4);
                    }
                }
            }
        }
    }
    return $r;
}
开发者ID:sgml,项目名称:rww.io,代码行数:29,代码来源:webid.lib.php

示例3: convert_uuencode

 function convert_uuencode($string)
 {
     // Sanity check
     if (!is_scalar($string)) {
         user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
         return false;
     }
     $u = 0;
     $encoded = '';
     while ($c = count($bytes = unpack('c*', substr($string, $u, 45)))) {
         $u += 45;
         $encoded .= pack('c', $c + 0x20);
         while ($c % 3) {
             $bytes[++$c] = 0;
         }
         foreach (array_chunk($bytes, 3) as $b) {
             $b0 = ($b[0] & 0xfc) >> 2;
             $b1 = (($b[0] & 0x3) << 4) + (($b[1] & 0xf0) >> 4);
             $b2 = (($b[1] & 0xf) << 2) + (($b[2] & 0xc0) >> 6);
             $b3 = $b[2] & 0x3f;
             $b0 = $b0 ? $b0 + 0x20 : 0x60;
             $b1 = $b1 ? $b1 + 0x20 : 0x60;
             $b2 = $b2 ? $b2 + 0x20 : 0x60;
             $b3 = $b3 ? $b3 + 0x20 : 0x60;
             $encoded .= pack('c*', $b0, $b1, $b2, $b3);
         }
         $encoded .= "\n";
     }
     // Add termination characters
     $encoded .= "`\n";
     return $encoded;
 }
开发者ID:casan,项目名称:eccube-2_13,代码行数:32,代码来源:convert_uuencode.php

示例4: fromBinary

 /**
  * Creates an UUID from a binary representation
  *
  * @param string $uuid
  * @param int    $version
  * @return UUID
  */
 public static function fromBinary($uuid, $version = \null)
 {
     if (\strlen($uuid) !== 16) {
         throw new \InvalidArgumentException("Must have exactly 16 bytes");
     }
     return new UUID(\unpack("N", \substr($uuid, 0, 4))[1], \unpack("N", \substr($uuid, 4, 4))[1], \unpack("N", \substr($uuid, 8, 4))[1], \unpack("N", \substr($uuid, 12, 4))[1], $version);
 }
开发者ID:ken77731,项目名称:PocketMine-0.13.0,代码行数:14,代码来源:UUID__32bit.php

示例5: Net_DNS_RR_SRV

 function Net_DNS_RR_SRV(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $a = unpack("@{$offset}/npreference/nweight/nport", $data);
             $offset += 6;
             list($target, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
             $this->preference = $a['preference'];
             $this->weight = $a['weight'];
             $this->port = $a['port'];
             $this->target = $target;
         }
     } else {
         ereg("([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+(.+)[ \t]*\$", $data, $regs);
         $this->preference = $regs[1];
         $this->weight = $regs[2];
         $this->port = $regs[3];
         $this->target = ereg_replace('(.*)\\.$', '\\1', $regs[4]);
     }
 }
开发者ID:beppenapo,项目名称:rmv,代码行数:26,代码来源:SRV.php

示例6: signature_split

 public function signature_split($orgfile, $input)
 {
     $info = unpack('n', fread($input, 2));
     $blocksize = $info[1];
     $this->info['transferid'] = mt_rand();
     $count = 0;
     $needed = array();
     $cache = $this->getCache();
     $prefix = $this->getPrefix();
     while (!feof($orgfile)) {
         $new_md5 = fread($input, 16);
         if (feof($input)) {
             break;
         }
         $data = fread($orgfile, $blocksize);
         $org_md5 = md5($data, true);
         if ($org_md5 == $new_md5) {
             $cache->set($prefix . $count, $data);
         } else {
             $needed[] = $count;
         }
         $count++;
     }
     return array('transferid' => $this->info['transferid'], 'needed' => $needed, 'count' => $count);
 }
开发者ID:noci2012,项目名称:owncloud,代码行数:25,代码来源:filechunking.php

示例7: load

 /**
  * Faz a leitura do arquivos e popula as variaveis.
  * @param $fileName nome do arquivo
  */
 function load($fileName)
 {
     $f = fopen($fileName, "rb");
     $header['magic'] = fread($f, 2);
     $header['version'] = unpack("Cmajor/Cminor", fread($f, 2));
     $this->version = (double) ($header['version']['major'] . "." . $header['version']['minor']);
     $header['count'] = freadb($f, 2, 'S');
     $header['unknown'] = freadb($f, 2, 'S');
     if ($header['magic'] !== self::MAGIC) {
         throw new UnexpectedValueException("Invalid magic header, found ({$header['magic']}) expected ({self->MAGIC})");
     }
     //Faz a leitura dos sprites.
     for ($i = 0; $i < $header['count']; ++$i) {
         $width = freadb($f, 2, 'S');
         $height = freadb($f, 2, 'S');
         $size = freadb($f, 2, 'S');
         $data = fread($f, $size);
         $this->list[] = new Sprite($width, $height, $data);
     }
     //Faz a leitura da paleta de cores
     for ($i = 0; $i < 256; ++$i) {
         $this->palette[$i] = unpack('Cred/Cgreen/Cblue/Calpha', fread($f, 4));
     }
     //Define a paleta para da Sprite lido
     for ($i = 0; $i < $header['count']; ++$i) {
         $this->list[$i]->setPalette($this->palette);
     }
     fclose($f);
 }
开发者ID:puring0815,项目名称:OpenKore,代码行数:33,代码来源:SpriteList.php

示例8: lookupByToken

 static function lookupByToken($token)
 {
     //Expecting well formatted token see getAuthToken routine for details.
     $matches = array();
     if (!preg_match(static::$token_regex, $token, $matches)) {
         return null;
     }
     //Unpack the user and ticket ids
     $matches += unpack('Vuid/Vtid', Base32::decode(strtolower(substr($matches['hash'], 0, 13))));
     $user = null;
     switch ($matches['type']) {
         case 'c':
             //Collaborator c
             if (($user = Collaborator::lookup($matches['uid'])) && $user->getTicketId() != $matches['tid']) {
                 $user = null;
             }
             break;
         case 'o':
             //Ticket owner
             if ($ticket = Ticket::lookup($matches['tid'])) {
                 if (($user = $ticket->getOwner()) && $user->getId() != $matches['uid']) {
                     $user = null;
                 }
             }
             break;
     }
     if (!$user || !$user instanceof TicketUser || strcasecmp($user->getAuthToken($matches['algo']), $token)) {
         return false;
     }
     return $user;
 }
开发者ID:gizur,项目名称:osticket,代码行数:31,代码来源:class.client.php

示例9: parseBinary

 /**
  * Parse binary data
  *
  * @param string $binaryData The binary data
  */
 public function parseBinary($binaryData)
 {
     if (!is_null($binaryData) && Util::binaryLength($binaryData) >= TAC_AUTHEN_REPLY_FIXED_FIELDS_SIZE) {
         $reply = unpack('C1status/C1flags/n1server_msgLenght/n1dataLenght', $binaryData);
         $this->status = $reply['status'];
         $this->flags = $reply['flags'];
         $this->msgLenght = $reply['server_msgLenght'];
         $this->dataLenght = $reply['dataLenght'];
         $checkLen = TAC_AUTHEN_REPLY_FIXED_FIELDS_SIZE + $this->msgLenght + $this->dataLenght;
         if (Util::binaryLength($binaryData) == $checkLen) {
             $unpackMask = 'a' . TAC_AUTHEN_REPLY_FIXED_FIELDS_SIZE . 'header';
             if ($this->msgLenght > 0) {
                 $unpackMask .= '/a' . $this->msgLenght . 'msg';
             }
             if ($this->dataLenght > 0) {
                 $unpackMask .= '/a' . $this->dataLenght . 'data';
             }
             $unpack = unpack($unpackMask, $binaryData);
             if ($this->msgLenght > 0) {
                 $this->msg = $unpack['msg'];
             }
             if ($this->dataLenght > 0) {
                 $this->data = $unpack['data'];
             }
         }
     }
 }
开发者ID:martinclaro,项目名称:tacacs-php,代码行数:32,代码来源:ReplyBody.php

示例10: sendsock

function sendsock($in)
{
    global $config;
    $service_port = $config['sockport'];
    $address = $config['sockhost'];
    if (!function_exists("socket_create")) {
        error_log(date("y-m-d H:i:s") . " 未启用socket模块\n", 3, "error.log");
        return null;
    }
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if ($socket === false) {
        error_log(date("y-m-d H:i:s") . "socket_create() failed, reason: " . socket_strerror(socket_last_error()) . "\n", 3, "error.log");
        return null;
    }
    $result = socket_connect($socket, $address, $service_port);
    if ($result === false) {
        error_log(date("y-m-d H:i:s") . "socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($socket)) . "\n", 3, "error.log");
        return null;
    }
    socket_write($socket, $in, strlen($in));
    $result = socket_read($socket, 8192);
    $arr = unpack("C*", $result);
    socket_close($socket);
    return $arr;
}
开发者ID:707wk,项目名称:mechanical_parking_system,代码行数:25,代码来源:index.php

示例11: handleRequest

 /**
  * 
  */
 public function handleRequest($fh)
 {
     while (!feof($fh)) {
         // Makes the handler compatable with command line testing and playdar resolver pipeline usage
         if (!($content = fread($fh, 4))) {
             break;
         }
         // get the length of the payload from the first 4 bytes:
         $len = current(unpack('N', $content));
         // bail on empty request.
         if ($len == 0) {
             continue;
         }
         // read $len bytes for the actual payload and assume it's a JSON object.
         $request = json_decode(fread($fh, $len));
         // Malformed request
         if (!isset($request->artist, $request->album)) {
             continue;
         }
         // Let's resolve this bitch
         $results = $this->resolve($request);
         // No results, bail
         if (!$results) {
             continue;
         }
         // Build response and send
         $response = (object) array('_msgtype' => 'results', 'qid' => $request->qid, 'results' => $results);
         $this->sendResponse($response);
     }
 }
开发者ID:RJ,项目名称:playdar-core,代码行数:33,代码来源:playdarresolver.php

示例12: load

 /**
  * @param string $bin Raw binary data from imagegif or file_get_contents
  *
  * @return GifByteStream
  */
 public function load($bin)
 {
     $bytes = unpack('H*', $bin);
     // Unpack as hex
     $bytes = $bytes[1];
     return new GifByteStream($bytes);
 }
开发者ID:kosinix,项目名称:grafika,代码行数:12,代码来源:GifHelper.php

示例13: phpfiwa_check

function phpfiwa_check($engine_properties)
{
    $dir = $engine_properties['dir'];
    $files = scandir($dir);
    $feeds = array();
    for ($i = 2; $i < count($files); $i++) {
        $filename_parts = explode(".", $files[$i]);
        $feedid = (int) $filename_parts[0];
        if ($feedid > 0 && !in_array($feedid, $feeds)) {
            $feeds[] = $feedid;
        }
    }
    $error_count = 0;
    $n = 0;
    foreach ($feeds as $id) {
        $error = false;
        $errormsg = "";
        // 1) Analyse meta file
        $feedname = "{$id}.meta";
        // CHECK 1: META FILE EXISTS
        if (!file_exists($dir . $feedname)) {
            print "[Meta file does not exist: {$id}]\n";
            $error = true;
        } else {
            $meta = new stdClass();
            $metafile = fopen($dir . $feedname, 'rb');
            fseek($metafile, 4);
            $tmp = unpack("I", fread($metafile, 4));
            $meta->start_time = $tmp[1];
            $tmp = unpack("I", fread($metafile, 4));
            $meta->nlayers = $tmp[1];
            for ($i = 0; $i < $meta->nlayers; $i++) {
                $tmp = unpack("I", fread($metafile, 4));
            }
            $meta->interval = array();
            for ($i = 0; $i < $meta->nlayers; $i++) {
                $tmp = unpack("I", fread($metafile, 4));
                $meta->interval[$i] = $tmp[1];
            }
            fclose($metafile);
            if ($meta->nlayers < 1 || $meta->nlayers > 4) {
                $errormsg .= "[nlayers out of range: " . $meta->nlayers . "]";
                $error = true;
            }
            if ($meta->start_time > 0 && filesize($dir . $id . "_0.dat") == 0) {
                $errormsg .= "[Start time set but datafile is empty]";
                $error = true;
            }
            if ($error) {
                print "Feed {$id} " . $errormsg . " [" . date("d:m:Y G:i", filemtime($dir . $feedname)) . "]\n";
            }
        }
        if ($error) {
            $error_count++;
        }
        $n++;
    }
    print "Error count: " . $error_count . "\n";
    print "Number of feeds: {$n}\n";
}
开发者ID:AndaDB,项目名称:usefulscripts,代码行数:60,代码来源:phpfiwa.php

示例14: readShort

 public function readShort()
 {
     $data = substr($this->contents, $this->offset, 2);
     $this->offset += 2;
     $unpack = unpack('v', $data);
     return $unpack[1];
 }
开发者ID:mefisto2009,项目名称:cstrike,代码行数:7,代码来源:BinaryReader.php

示例15: parseIpBuffer

 /**
  * @param Buffer $ip
  * @return string
  * @throws \Exception
  */
 private function parseIpBuffer(Buffer $ip)
 {
     $end = $ip->slice(12, 4);
     return implode(".", array_map(function ($int) {
         return unpack("C", $int)[1];
     }, str_split($end->getBinary(), 1)));
 }
开发者ID:tokenly,项目名称:bitcoin-p2p-php,代码行数:12,代码来源:NetworkAddressTimestampSerializer.php


注:本文中的unpack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。