• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP pack函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getRandomBytes

 private function getRandomBytes($count)
 {
     $bytes = '';
     if (function_exists('openssl_random_pseudo_bytes') && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
         // OpenSSL slow on Win
         $bytes = openssl_random_pseudo_bytes($count);
     }
     if ($bytes === '' && @is_readable('/dev/urandom') && ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) {
         $bytes = fread($hRand, $count);
         fclose($hRand);
     }
     if (strlen($bytes) < $count) {
         $bytes = '';
         if ($this->randomState === null) {
             $this->randomState = microtime();
             if (function_exists('getmypid')) {
                 $this->randomState .= getmypid();
             }
         }
         for ($i = 0; $i < $count; $i += 16) {
             $this->randomState = md5(microtime() . $this->randomState);
             if (PHP_VERSION >= '5') {
                 $bytes .= md5($this->randomState, true);
             } else {
                 $bytes .= pack('H*', md5($this->randomState));
             }
         }
         $bytes = substr($bytes, 0, $count);
     }
     return $bytes;
 }
开发者ID:vkaran101,项目名称:sase,代码行数:31,代码来源:Bcrypt.php


示例2: 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


示例3: hex2bin

 function hex2bin($input, $assume_safe = true)
 {
     if ($assume_safe !== true && !(strlen($input) % 2 === 0 || preg_match('/^[0-9a-f]+$/i', $input))) {
         return '';
     }
     return pack('H*', $input);
 }
开发者ID:Q8HMA,项目名称:BtiTracker-1.5.1,代码行数:7,代码来源:common.php


示例4: encryptMsg

 public function encryptMsg($text)
 {
     $token = $this->account['token'];
     $encodingaeskey = $this->account['encodingaeskey'];
     $appid = $this->account['key'];
     $key = base64_decode($encodingaeskey . '=');
     $text = random(16) . pack("N", strlen($text)) . $text . $appid;
     $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
     $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     $iv = substr($key, 0, 16);
     $block_size = 32;
     $text_length = strlen($text);
     $amount_to_pad = $block_size - $text_length % $block_size;
     if ($amount_to_pad == 0) {
         $amount_to_pad = $block_size;
     }
     $pad_chr = chr($amount_to_pad);
     $tmp = '';
     for ($index = 0; $index < $amount_to_pad; $index++) {
         $tmp .= $pad_chr;
     }
     $text = $text . $tmp;
     mcrypt_generic_init($module, $key, $iv);
     $encrypted = mcrypt_generic($module, $text);
     mcrypt_generic_deinit($module);
     mcrypt_module_close($module);
     $encrypt_msg = base64_encode($encrypted);
     $signature = $this->buildSignature($encrypt_msg);
     return array($signature, $encrypt_msg);
 }
开发者ID:7demo,项目名称:we7,代码行数:30,代码来源:weixin.account.class.php


示例5: storeDocuments

 public function storeDocuments($name, array $documents = null)
 {
     if ($name === null || $documents === null || trim($name) == '') {
         return false;
     }
     if (!is_string($name) || !is_array($documents)) {
         return false;
     }
     foreach ($documents as $doc) {
         if (!$this->validateDocument($doc)) {
             return false;
         }
     }
     $fp = fopen($this->_getFilePathName($name), 'w');
     foreach ($documents as $doc) {
         $bindata1 = pack('i', intval($doc[0]));
         $bindata2 = pack('i', intval($doc[1]));
         $bindata3 = pack('i', intval($doc[2]));
         fwrite($fp, $bindata1);
         fwrite($fp, $bindata2);
         fwrite($fp, $bindata3);
     }
     fclose($fp);
     return true;
 }
开发者ID:thegeekajay,项目名称:search-engine,代码行数:25,代码来源:multifolderindex.class.php


示例6: appendHeader

 protected function appendHeader($request, $id = null)
 {
     if ($id === null) {
         $id = $this->getId();
     }
     return pack("NN", strlen($request) | 0x80000000, $id) . $request;
 }
开发者ID:wanggeopens,项目名称:own-libs,代码行数:7,代码来源:FullDuplexTransporter.php


示例7: chapchallengeresponse

function chapchallengeresponse($challenge, $password)
{
    // Generates a response for a challenge response CHAP Auth
    $hexChallenge = pack("H32", $challenge);
    $response = md5("" . $password . $hexChallenge);
    return $response;
}
开发者ID:KuberKode,项目名称:grase-www-portal,代码行数:7,代码来源:automacusers.php


示例8: convertip_tiny

 public function convertip_tiny($ip, $ipdatafile)
 {
     static $fp = NULL, $offset = array(), $index = NULL;
     $ipdot = explode('.', $ip);
     $ip = pack('N', ip2long($ip));
     $ipdot[0] = (int) $ipdot[0];
     $ipdot[1] = (int) $ipdot[1];
     if ($fp === NULL && ($fp = @fopen($ipdatafile, 'rb'))) {
         $offset = @unpack('Nlen', @fread($fp, 4));
         $index = @fread($fp, $offset['len'] - 4);
     } elseif ($fp == FALSE) {
         return '- Invalid IP data file';
     }
     $length = $offset['len'] - 1028;
     $start = @unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
     for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {
         if ($index[$start] . $index[$start + 1] . $index[$start + 2] . $index[$start + 3] >= $ip) {
             $index_offset = @unpack('Vlen', $index[$start + 4] . $index[$start + 5] . $index[$start + 6] . "");
             $index_length = @unpack('Clen', $index[$start + 7]);
             break;
         }
     }
     @fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
     if ($index_length['len']) {
         return '- ' . @fread($fp, $index_length['len']);
     } else {
         return '- Unknown';
     }
 }
开发者ID:a195474368,项目名称:ejiawang,代码行数:29,代码来源:location.mdl.php


示例9: chr

 /**
  * Returns a specific character in UTF-8.
  * @param  int     codepoint
  * @return string
  */
 public static function chr($code)
 {
     if (func_num_args() > 1 && strcasecmp(func_get_arg(1), 'UTF-8')) {
         trigger_error(__METHOD__ . ' supports only UTF-8 encoding.', E_USER_DEPRECATED);
     }
     return iconv('UTF-32BE', 'UTF-8//IGNORE', pack('N', $code));
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:12,代码来源:Strings.php


示例10: encrypt

 /**
  * The symmetric encryption function
  *
  * @param string $pwd Key to encrypt with (can be binary of hex)
  * @param string $data Content to be encrypted
  * @param bool $ispwdHex Key passed is in hexadecimal or not
  * @access public
  * @return string
  */
 function encrypt($pwd, $data, $ispwdHex = 0)
 {
     if ($ispwdHex) {
         $pwd = @pack('H*', $pwd);
     }
     // valid input, please!
     $key[] = '';
     $box[] = '';
     $cipher = '';
     $pwd_length = strlen($pwd);
     $data_length = strlen($data);
     for ($i = 0; $i < 256; $i++) {
         $key[$i] = ord($pwd[$i % $pwd_length]);
         $box[$i] = $i;
     }
     for ($j = $i = 0; $i < 256; $i++) {
         $j = ($j + $box[$i] + $key[$i]) % 256;
         $tmp = $box[$i];
         $box[$i] = $box[$j];
         $box[$j] = $tmp;
     }
     for ($a = $j = $i = 0; $i < $data_length; $i++) {
         $a = ($a + 1) % 256;
         $j = ($j + $box[$a]) % 256;
         $tmp = $box[$a];
         $box[$a] = $box[$j];
         $box[$j] = $tmp;
         $k = $box[($box[$a] + $box[$j]) % 256];
         $cipher .= chr(ord($data[$i]) ^ $k);
     }
     return $cipher;
 }
开发者ID:alesconti,项目名称:FF_2015,代码行数:41,代码来源:rc4.php


示例11: pbkdf2

function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
    $algorithm = strtolower($algorithm);
    if (!in_array($algorithm, hash_algos(), true)) {
        die('PBKDF2 ERROR: Invalid hash algorithm.');
    }
    if ($count <= 0 || $key_length <= 0) {
        die('PBKDF2 ERROR: Invalid parameters.');
    }
    $hash_length = strlen(hash($algorithm, "", true));
    $block_count = ceil($key_length / $hash_length);
    $output = "";
    for ($i = 1; $i <= $block_count; $i++) {
        // $i encoded as 4 bytes, big endian.
        $last = $salt . pack("N", $i);
        // first iteration
        $last = $xorsum = hash_hmac($algorithm, $last, $password, true);
        // perform the other $count - 1 iterations
        for ($j = 1; $j < $count; $j++) {
            $xorsum ^= $last = hash_hmac($algorithm, $last, $password, true);
        }
        $output .= $xorsum;
    }
    if ($raw_output) {
        return substr($output, 0, $key_length);
    } else {
        return bin2hex(substr($output, 0, $key_length));
    }
}
开发者ID:Ayeblinken,项目名称:potonka,代码行数:29,代码来源:password_helper.php


示例12: parse

 public function parse()
 {
     $matches = array();
     if ($this->softmode) {
         $res = preg_match(self::PATTERN_SOFTMODE, trim($this->fileContent), $matches);
     } else {
         $res = preg_match(self::PATTERN, $this->fileContent, $matches);
     }
     if ($res === false || $res === 0) {
         throw new \Exception($this->filename . ' is not a proper .srt file.');
     }
     $this->setLineEnding($matches[1]);
     $bom = pack('CCC', 0xef, 0xbb, 0xbf);
     $matches = explode($this->lineEnding . $this->lineEnding, trim($matches[0], $bom . $this->lineEnding));
     $subtitleOrder = 1;
     $subtitleTime = '';
     foreach ($matches as $match) {
         $subtitle = explode($this->lineEnding, $match, 3);
         $timeline = explode(' --> ', $subtitle[1]);
         $subtitleTimeStart = $timeline[0];
         $subtitleTimeEnd = $timeline[1];
         if (!$this->softmode && ($subtitle[0] != $subtitleOrder++ || !$this->validateTimelines($subtitleTime, $subtitleTimeStart, true) || !$this->validateTimelines($subtitleTimeStart, $subtitleTimeEnd))) {
             throw new \Exception($this->filename . ' is not a proper .srt file.');
         }
         $subtitleTime = $subtitleTimeEnd;
         $cue = new SubripCue($timeline[0], $timeline[1], isset($subtitle[2]) ? $subtitle[2] : '');
         $cue->setLineEnding($this->lineEnding);
         $this->addCue($cue);
     }
     return $this;
 }
开发者ID:sovic,项目名称:captioning,代码行数:31,代码来源:SubripFile.php


示例13: hexstr

function hexstr($hexstr)
{
    $hexstr = str_replace(' ', '', $hexstr);
    $hexstr = str_replace('\\x', '', $hexstr);
    $retstr = pack('H*', $hexstr);
    return $retstr;
}
开发者ID:rgfretes,项目名称:hotel-center-vcp,代码行数:7,代码来源:sendmail.php


示例14: getData

 /**
  * Generate the WSBOOL biff record
  * @param Worksheet $sheet
  *
  * @return string
  */
 public function getData(Worksheet $sheet)
 {
     $grbit = 0x0;
     // Set the option flags
     $grbit |= 0x1;
     // Auto page breaks visible
     if ($sheet->getOutlineStyle()) {
         $grbit |= 0x20;
         // Auto outline styles
     }
     if ($sheet->getOutlineBelow()) {
         $grbit |= 0x40;
         // Outline summary below
     }
     if ($sheet->getOutlineRight()) {
         $grbit |= 0x80;
         // Outline summary right
     }
     if ($sheet->getPrintSetup()->isFitPage()) {
         $grbit |= 0x100;
         // Page setup fit to page
     }
     if ($sheet->isOutlineOn()) {
         $grbit |= 0x400;
         // Outline symbols displayed
     }
     $data = pack("v", $grbit);
     return $this->getFullRecord($data);
 }
开发者ID:maxakawizard,项目名称:xls-writer,代码行数:35,代码来源:WsBool.php


示例15: removeBom

 /**
  * Remove the byte order mark from a string if applicable
  *
  * @param string $string
  * @return string
  */
 public static function removeBom($string)
 {
     if (substr($string, 0, 3) == pack('CCC', 0xef, 0xbb, 0xbf)) {
         $string = substr($string, 3);
     }
     return $string;
 }
开发者ID:oat-sa,项目名称:jig,代码行数:13,代码来源:StringUtils.php


示例16: each

 /**
  * This method iterates over each record in the file, yielding each item to the procedure function.
  *
  * @access public
  * @param callable $procedure                               the procedure function to be used
  * @throws Throwable\Parse\Exception                        indicates that an invalid record was
  *                                                          encountered
  */
 public function each(callable $procedure)
 {
     $self = $this;
     IO\FileReader::read($this->file, function ($reader, $data, $index) use($self, $procedure) {
         $line = trim($data);
         if (strlen($line) > 0) {
             if ($index == 0 && $self->bom) {
                 $line = preg_replace('/^' . pack('H*', 'EFBBBF') . '/', '', $line);
             }
             $query_string = parse_url($line, PHP_URL_QUERY);
             $properties = array();
             parse_str($query_string, $properties);
             if (!empty($properties)) {
                 $source_encoding = $self->encoder !== null ? call_user_func($self->encoder . "::getEncoding", $properties) : $self->encoding[0];
                 $target_encoding = $self->encoding[1];
                 foreach ($properties as $key => &$value) {
                     $value = urldecode($value);
                     $value = Core\Data\Charset::encode($value, $source_encoding, $target_encoding);
                     $type = isset($self->schema[$key]) ? $self->schema[$key] : 'string';
                     $value = Core\Convert::changeType($value, $type);
                     $record = new Common\Mutable\HashMap();
                     $record->putEntry($key, $value);
                     $procedure($record);
                 }
             }
         }
     });
 }
开发者ID:bluesnowman,项目名称:Chimera,代码行数:36,代码来源:Reader.php


示例17: Qiniu_PutFile

function Qiniu_PutFile($upToken, $key, $localFile, $putExtra)
{
    global $QINIU_UP_HOST;
    if ($putExtra === null) {
        $putExtra = new Qiniu_PutExtra();
    }
    if (!empty($putExtra->MimeType)) {
        $localFile .= ';type=' . $putExtra->MimeType;
    }
    $fields = array('token' => $upToken, 'file' => '@' . $localFile);
    if ($key === null) {
        $fname = '?';
    } else {
        $fname = $key;
        $fields['key'] = $key;
    }
    if ($putExtra->CheckCrc) {
        if ($putExtra->CheckCrc === 1) {
            $hash = hash_file('crc32b', $localFile);
            $array = unpack('N', pack('H*', $hash));
            $putExtra->Crc32 = $array[1];
        }
        $fields['crc32'] = sprintf('%u', $putExtra->Crc32);
    }
    $client = new Qiniu_HttpClient();
    return Qiniu_Client_CallWithForm($client, $QINIU_UP_HOST, $fields, 'multipart/form-data');
}
开发者ID:duxiangfei,项目名称:plugins,代码行数:27,代码来源:io.php


示例18: inet_pton

 function inet_pton($ip)
 {
     # ipv4
     if (strpos($ip, '.') !== FALSE) {
         if (strpos($ip, ':') === FALSE) {
             $ip = pack('N', ip2long($ip));
         } else {
             $ip = explode(':', $ip);
             $ip = pack('N', ip2long($ip[count($ip) - 1]));
         }
     } elseif (strpos($ip, ':') !== FALSE) {
         $ip = explode(':', $ip);
         $parts = 8 - count($ip);
         $res = '';
         $replaced = 0;
         foreach ($ip as $seg) {
             if ($seg != '') {
                 $res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
             } elseif ($replaced == 0) {
                 for ($i = 0; $i <= $parts; $i++) {
                     $res .= '0000';
                 }
                 $replaced = 1;
             } elseif ($replaced == 1) {
                 $res .= '0000';
             }
         }
         $ip = pack('H' . strlen($res), $res);
     }
     return $ip;
 }
开发者ID:RicterZ,项目名称:pixmicat,代码行数:31,代码来源:lib_common.php


示例19: pbkdf2

 /**
  * PBKDF2 Implementation for deriving keys.
  *
  * @param   string   $p   Password
  * @param   string   $s   Salt
  * @param   integer  $kl  Key length
  * @param   integer  $c   Iteration count
  * @param   string   $a   Hash algorithm
  *
  * @return  string  The derived key.
  *
  * @see     http://en.wikipedia.org/wiki/PBKDF2
  * @see     http://www.ietf.org/rfc/rfc2898.txt
  * 
  * @copyright   Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
  */
 protected static function pbkdf2($p, $s, $kl, $c = 10000, $a = 'sha256')
 {
     // simple md5 version
     if (!function_exists('hash')) {
         $seed = $p . $s;
         $md5 = md5($seed);
         for ($i = 0; $i < $c; $i++) {
             $md5 = md5($md5 . md5(rand(0, 2147483647)));
         }
         return substr($md5, 0, $kl);
     }
     // Hash length.
     $hl = strlen(hash($a, null, true));
     // Key blocks to compute.
     $kb = ceil($kl / $hl);
     // Derived key.
     $dk = '';
     // Create the key.
     for ($block = 1; $block <= $kb; $block++) {
         // Initial hash for this block.
         $ib = $b = hash_hmac($a, $s . pack('N', $block), $p, true);
         // Perform block iterations.
         for ($i = 1; $i < $c; $i++) {
             $ib ^= $b = hash_hmac($a, $b, $p, true);
         }
         // Append the iterated block.
         $dk .= $ib;
     }
     // Return derived key of correct length.
     return substr($dk, 0, $kl);
 }
开发者ID:jimyb3,项目名称:mathematicalteachingsite,代码行数:47,代码来源:encrypt.php


示例20: sendNotificationIOS

function sendNotificationIOS()
{
    // Put your device token here (without spaces):
    $deviceToken = '87d4477b81a7f8f7ba80b3f5f043d83dec3c9b0940c708d24f803ef67600966f';
    // Put your private key's passphrase here:
    $passphrase = 'pushchat';
    // Put your alert message here:
    $message = 'My first push notification!';
    ////////////////////////////////////////////////////////////////////////////////
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
    // Open a connection to the APNS server
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);
    if (!$fp) {
        exit("Failed to connect: {$err} {$errstr}" . PHP_EOL);
    }
    echo 'Connected to APNS' . PHP_EOL;
    // Create the payload body
    $body['aps'] = array('alert' => $message, 'sound' => 'default');
    // Encode the payload as JSON
    $payload = json_encode($body);
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));
    if (!$result) {
        echo 'Message not delivered' . PHP_EOL;
    } else {
        echo 'Message successfully delivered' . PHP_EOL;
    }
    // Close the connection to the server
    fclose($fp);
}
开发者ID:armoving,项目名称:nayaritenlinea,代码行数:34,代码来源:complete.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP pack_fee函数代码示例发布时间:2022-05-15
下一篇:
PHP p_wiki_xhtml函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap