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


PHP bin2hex函数代码示例

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


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

示例1: my_inet_ntop

function my_inet_ntop($ip)
{
    if (strlen($ip) == 4) {
        // ipv4
        list(, $ip) = unpack('N', $ip);
        $ip = long2ip($ip);
    } elseif (strlen($ip) == 16) {
        // ipv6
        $ip = bin2hex($ip);
        $ip = substr(chunk_split($ip, 4, ':'), 0, -1);
        $ip = explode(':', $ip);
        $res = '';
        foreach ($ip as $seg) {
            while ($seg[0] == '0') {
                $seg = substr($seg, 1);
            }
            if ($seg != '') {
                $res .= ($res == '' ? '' : ':') . $seg;
            } else {
                if (strpos($res, '::') === false) {
                    if (substr($res, -1) == ':') {
                        continue;
                    }
                    $res .= ':';
                    continue;
                }
                $res .= ($res == '' ? '' : ':') . '0';
            }
        }
        $ip = $res;
    }
    return $ip;
}
开发者ID:Bigjoos,项目名称:U-232-V5,代码行数:33,代码来源:view_peers.php

示例2: getexif

function getexif($img)
{
    $imgtype = array("", "GIF", "JPG", "PNG", "SWF", "PSD", "BMP", "TIFF(intel byte order)", "TIFF(motorola byte order)", "JPC", "JP2", "JPX", "JB2", "SWC", "IFF", "WBMP", "XBM");
    $Orientation = array("", "top left side", "top right side", "bottom right side", "bottom left side", "left side top", "right side top", "right side bottom", "left side bottom");
    $ResolutionUnit = exif_lang('resolutionunit');
    $YCbCrPositioning = array("", "the center of pixel array", "the datum point");
    $ExposureProgram = exif_lang('exposureprogram');
    $MeteringMode_arr = exif_lang('meteringmode');
    $Lightsource_arr = exif_lang('lightsource');
    $Flash_arr = array("0" => "flash did not fire", "1" => "flash fired", "5" => "flash fired but strobe return light not detected", "7" => "flash fired and strobe return light detected");
    if (!function_exists('exif_read_data')) {
        return exif_lang('img_info');
    }
    $exif = @exif_read_data($img, "IFD0");
    if ($exif === false) {
        $new_img_info = exif_lang('img_info');
    } else {
        @($exif = exif_read_data($img, 0, true));
        foreach ($exif as $type => $typearr) {
            foreach ($typearr as $key => $kval) {
                if (is_array($kval)) {
                    foreach ($kval as $vkey => $value) {
                        $str = dhtmlspecialchars(preg_replace("/[^\\[A-Za-z0-9_\\.\\/:\\s-\\]]/", '', trim($value)));
                        $exif[$type][$key][$vkey] = $str;
                    }
                } elseif (!in_array($key, array('ComponentsConfiguration', 'FileSource', 'SceneType'))) {
                    $str = dhtmlspecialchars(preg_replace("/[^\\[A-Za-z0-9_\\.\\/:\\s-\\]]/", '', trim($kval)));
                    $exif[$type][$key] = $str;
                }
            }
        }
        $new_img_info = array(exif_lang('FileName') => $exif[FILE][FileName], exif_lang('FileType') => $imgtype[$exif[FILE][FileType]], exif_lang('MimeType') => $exif[FILE][MimeType], exif_lang('FileSize') => $exif[FILE][FileSize], exif_lang('FileDateTime') => date("Y-m-d H:i:s", $exif[FILE][FileDateTime]), exif_lang('ImageDescription') => $exif[IFD0][ImageDescription], exif_lang('Make') => $exif[IFD0][Make], exif_lang('Model') => $exif[IFD0][Model], exif_lang('Orientation') => $Orientation[$exif[IFD0][Orientation]], exif_lang('XResolution') => $exif[IFD0][XResolution] . $ResolutionUnit[$exif[IFD0][ResolutionUnit]], exif_lang('YResolution') => $exif[IFD0][YResolution] . $ResolutionUnit[$exif[IFD0][ResolutionUnit]], exif_lang('Software') => $exif[IFD0][Software], exif_lang('DateTime') => $exif[IFD0][DateTime], exif_lang('Artist') => $exif[IFD0][Artist], exif_lang('YCbCrPositioning') => $YCbCrPositioning[$exif[IFD0][YCbCrPositioning]], exif_lang('Copyright') => $exif[IFD0][Copyright], exif_lang('Photographer') => $exif[COMPUTED][Copyright . Photographer], exif_lang('Editor') => $exif[COMPUTED][Copyright . Editor], exif_lang('ExifVersion') => $exif[EXIF][ExifVersion], exif_lang('FlashPixVersion') => "Ver. " . number_format($exif[EXIF][FlashPixVersion] / 100, 2), exif_lang('DateTimeOriginal') => $exif[EXIF][DateTimeOriginal], exif_lang('DateTimeDigitized') => $exif[EXIF][DateTimeDigitized], exif_lang('Height') => $exif[COMPUTED][Height], exif_lang('Width') => $exif[COMPUTED][Width], exif_lang('ApertureValue') => $exif[EXIF][ApertureValue], exif_lang('ShutterSpeedValue') => $exif[EXIF][ShutterSpeedValue], exif_lang('ApertureFNumber') => $exif[COMPUTED][ApertureFNumber], exif_lang('MaxApertureValue') => "F" . $exif[EXIF][MaxApertureValue], exif_lang('ExposureTime') => $exif[EXIF][ExposureTime], exif_lang('FNumber') => $exif[EXIF][FNumber], exif_lang('MeteringMode') => getimageinfoval($exif[EXIF][MeteringMode], $MeteringMode_arr), exif_lang('LightSource') => getimageinfoval($exif[EXIF][LightSource], $Lightsource_arr), exif_lang('Flash') => getimageinfoval($exif[EXIF][Flash], $Flash_arr), exif_lang('ExposureMode') => $exif[EXIF][ExposureMode] == 1 ? exif_lang('manual') : exif_lang('auto'), exif_lang('WhiteBalance') => $exif[EXIF][WhiteBalance] == 1 ? exif_lang('manual') : exif_lang('auto'), exif_lang('ExposureProgram') => $ExposureProgram[$exif[EXIF][ExposureProgram]], exif_lang('ExposureBiasValue') => $exif[EXIF][ExposureBiasValue] . "EV", exif_lang('ISOSpeedRatings') => $exif[EXIF][ISOSpeedRatings], exif_lang('ComponentsConfiguration') => bin2hex($exif[EXIF][ComponentsConfiguration]) == "01020300" ? "YCbCr" : "RGB", exif_lang('CompressedBitsPerPixel') => $exif[EXIF][CompressedBitsPerPixel] . "Bits/Pixel", exif_lang('FocusDistance') => $exif[COMPUTED][FocusDistance] . "m", exif_lang('FocalLength') => $exif[EXIF][FocalLength] . "mm", exif_lang('FocalLengthIn35mmFilm') => $exif[EXIF][FocalLengthIn35mmFilm] . "mm", exif_lang('UserCommentEncoding') => $exif[COMPUTED][UserCommentEncoding], exif_lang('UserComment') => $exif[COMPUTED][UserComment], exif_lang('ColorSpace') => $exif[EXIF][ColorSpace] == 1 ? "sRGB" : "Uncalibrated", exif_lang('ExifImageLength') => $exif[EXIF][ExifImageLength], exif_lang('ExifImageWidth') => $exif[EXIF][ExifImageWidth], exif_lang('FileSource') => bin2hex($exif[EXIF][FileSource]) == 0x3 ? "digital still camera" : "unknown", exif_lang('SceneType') => bin2hex($exif[EXIF][SceneType]) == 0x1 ? "A directly photographed image" : "unknown", exif_lang('ThumbFileType') => $exif[COMPUTED][Thumbnail . FileType], exif_lang('ThumbMimeType') => $exif[COMPUTED][Thumbnail . MimeType]);
    }
    return $new_img_info;
}
开发者ID:softhui,项目名称:discuz,代码行数:35,代码来源:function_exif.php

示例3: getHexData

 public function getHexData($chunkSplit = 0, $sep = ' ')
 {
     if ($chunkSplit) {
         return chunk_split(bin2hex($this->_data), (int) $chunkSplit, (string) $sep);
     }
     return bin2hex($this->_data);
 }
开发者ID:Sect0R,项目名称:WOOPS,代码行数:7,代码来源:DataAtom.class.php

示例4: register

 public function register()
 {
     $this->form_validation->set_rules('first_name', 'First Name', 'required|trim|alpha|min_length[2]');
     $this->form_validation->set_rules('last_name', 'Last Name', 'required|trim|alpha|min_length[2]');
     $this->form_validation->set_rules('alias', 'Alias', 'required|min_length[3]');
     $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email|is_unique[users.email]');
     $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]');
     $this->form_validation->set_rules('password2', 'Confirm Password', 'required|matches[password]');
     $this->form_validation->set_rules('birthdate', 'Birthdate', 'required');
     if ($this->form_validation->run() == FALSE) {
         $this->session->set_flashdata('registration_errors', validation_errors());
         redirect('');
     } else {
         $this->load->model('User');
         $post = $this->input->post();
         $pass = $post['password'];
         $salt = bin2hex(openssl_random_pseudo_bytes(22));
         $hash = crypt($pass, $salt);
         $post['password'] = $hash;
         $user = $this->User->register_user($post);
         if ($user > 0) {
             $this->session->set_userdata('id', $user);
             $this->session->set_userdata('name', $post['first_name']);
             $this->session->set_userdata('loggedin', TRUE);
             $this->session->set_flashdata('success', 'Thank you for registering, please log in!');
             redirect('');
         } else {
             $this->session->set_flashdata('registration_errors', 'There was a system error, plese try again later!');
             redirect('');
         }
     }
 }
开发者ID:jpkoren,项目名称:Quotable-Quotes,代码行数:32,代码来源:users.php

示例5: testHex2binThree

 public function testHex2binThree()
 {
     $data = "וּמִפְּרִ֣י הָעֵץ֮ אֲשֶׁ֣ר בְּתוֹךְ־הַגָּן֒ אָמַ֣ר אֱלֹהִ֗ים לֹ֤א תֹֽאכְלוּ֙ מִמֶּ֔נּוּ וְלֹ֥א תִגְּע֖וּ בּ֑וֹ פֶּן־תְּמֻתֽוּן׃ ";
     $hex = bin2hex($data);
     $this->assertEquals($data, hex2bin($hex));
     $this->assertEquals($data, Filter_Hex::hex2bin($hex));
 }
开发者ID:alerque,项目名称:bibledit,代码行数:7,代码来源:hexTest.php

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

示例7: smarty_modifier_escape

function smarty_modifier_escape($string, $esc_type = 'html')
{
    switch ($esc_type) {
        case 'html':
            return htmlspecialchars($string, ENT_QUOTES);
        case 'htmlall':
            return htmlentities($string, ENT_QUOTES);
        case 'url':
            return urlencode($string);
        case 'quotes':
            // escape unescaped single quotes
            return preg_replace("%(?<!\\\\)'%", "\\'", $string);
        case 'hex':
            // escape every character into hex
            for ($x = 0; $x < strlen($string); $x++) {
                $return .= '%' . bin2hex($string[$x]);
            }
            return $return;
        case 'hexentity':
            for ($x = 0; $x < strlen($string); $x++) {
                $return .= '&#x' . bin2hex($string[$x]) . ';';
            }
            return $return;
        case 'javascript':
            // escape quotes and backslashes and newlines
            return str_replace(array('\\', '\'', "\r", "\n"), array("\\\\", "\\'", '\\r', '\\r'), $string);
        default:
            return $string;
    }
}
开发者ID:BackupTheBerlios,项目名称:logicalframe,代码行数:30,代码来源:modifier.escape.php

示例8: getVisitorId

 function getVisitorId()
 {
     if (isset($this->details['idvisitor'])) {
         return bin2hex($this->details['idvisitor']);
     }
     return false;
 }
开发者ID:KingNoosh,项目名称:Teknik,代码行数:7,代码来源:Visitor.php

示例9: computeSign

 public function computeSign($sharedSecret)
 {
     if (!$this->isValid) {
         throw new Exception(__METHOD__ . ": Message was not validated.");
     }
     try {
         $bytesHash = sha1($this->GetSignatureBase(), true);
         $sharedSecret = pack('H*', $sharedSecret);
         // uprava pre PHP < 5.0
         if (strlen($bytesHash) != 20) {
             $bytes = "";
             for ($i = 0; $i < strlen($bytesHash); $i += 2) {
                 $bytes .= chr(hexdec(substr($str, $i, 2)));
             }
             $bytesHash = $bytes;
         }
         $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_ECB, "");
         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($cipher), MCRYPT_RAND);
         mcrypt_generic_init($cipher, $sharedSecret, $iv);
         $text = $this->pad(substr($bytesHash, 0, 16), mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
         $bytesSign = mcrypt_generic($cipher, $text);
         mcrypt_generic_deinit($cipher);
         mcrypt_module_close($cipher);
         $sign = substr(strtoupper(bin2hex($bytesSign)), 0, 32);
     } catch (Exception $e) {
         return false;
     }
     return $sign;
 }
开发者ID:martinstrycek,项目名称:php-payments,代码行数:29,代码来源:EPaymentAesSignedMessage.class.php

示例10: encrypt

 /**
  * Encrypt the given value.
  *
  * @param string $value
  * 
  * @return string
  */
 private function encrypt($value)
 {
     if ($this->cipher) {
         return bin2hex($this->cipher->encrypt($value));
     }
     return $value;
 }
开发者ID:snapshotpl,项目名称:psr7-middlewares,代码行数:14,代码来源:CryptTrait.php

示例11: testDerive

 /**
  * @covers CryptLib\Key\Derivation\KDF\KDF1
  * @dataProvider provideTestDerive
  * @group slow
  */
 public function testDerive($p, $len, $data, $expect)
 {
     $pb = new KDF1();
     $actual = $pb->derive($p, $len, $data);
     $actual = bin2hex($actual);
     $this->assertEquals($expect, $actual);
 }
开发者ID:nimasdj,项目名称:PHP-CryptLib,代码行数:12,代码来源:KDF1Test.php

示例12: login

 public function login(Request $request)
 {
     $input = $request->json()->all();
     $validator = Validator::make($input, ['email' => 'required|email', 'password' => 'required', 'deviceId' => 'required']);
     if ($validator->fails()) {
         $error = $validator->errors()->all();
         return response()->json(['errorMessage' => [$error]], 404);
     }
     $deviceId = $input['deviceId'];
     $result = DB::table('users')->where('email', $input['email'])->first();
     if ($result && Hash::check($input['password'], $result->password)) {
         $res = DB::table('tokens')->where('deviceId', $deviceId)->first();
         if ($res) {
             $token = Token::find($res->id);
             $token->token = bin2hex(openssl_random_pseudo_bytes(64));
             $token->save();
         } else {
             DB::table('tokens')->insert(['token' => bin2hex(openssl_random_pseudo_bytes(64)), 'userId' => $result->id, 'deviceId' => $deviceId]);
         }
         $token = DB::table('tokens')->select('token')->where('userId', $result->id)->where('deviceId', $deviceId)->first();
         if ($token) {
             return response()->json($token);
         } else {
             return response()->json(['errorMessage' => 'login failed'], 404);
         }
     } else {
         return response()->json(['errorMessage' => 'this user not found'], 404);
     }
 }
开发者ID:48group,项目名称:Eastland-Server-Side,代码行数:29,代码来源:UserController.php

示例13: smarty_modifier_escape

/**
 * Smarty escape modifier plugin
 *
 * Type:     modifier<br>
 * Name:     escape<br>
 * Purpose:  escape string for output
 *
 * @link   http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)
 * @author Monte Ohrt <monte at ohrt dot com>
 * @param  string  $string        input string
 * @param  string  $esc_type      escape type
 * @param  string  $char_set      character set, used for htmlspecialchars() or htmlentities()
 * @param  boolean $double_encode encode already encoded entitites again, used for htmlspecialchars() or htmlentities()
 * @return string escaped input string
 */
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'UTF-8', $double_encode = true)
{
    switch ($esc_type) {
        case 'html':
            return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
        case 'url':
            return rawurlencode($string);
        case 'urlpathinfo':
            return str_replace('%2F', '/', rawurlencode($string));
        case 'quotes':
            // escape unescaped single quotes
            return preg_replace("%(?<!\\\\)'%", "\\'", $string);
        case 'hex':
            // escape every byte into hex
            // Note that the UTF-8 encoded character ä will be represented as %c3%a4
            $return = '';
            $_length = strlen($string);
            for ($x = 0; $x < $_length; $x++) {
                $return .= '%' . bin2hex($string[$x]);
            }
            return $return;
        case 'javascript':
            // escape quotes and backslashes, newlines, etc.
            return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\\/'));
        default:
            throw new Exception('Unrecognized escape option "' . $esc_type . '"');
    }
}
开发者ID:jeantimex,项目名称:brainy,代码行数:43,代码来源:modifier.escape.php

示例14: ecryptdString

	protected function ecryptdString($str,$keys="6461772803150152",$iv="8105547186756005",$cipher_alg=MCRYPT_RIJNDAEL_128){
		//
		//
		//source_id=xxx&target_id=xxx&type=1
		$encrypted_string = bin2hex(mcrypt_encrypt($cipher_alg, $keys, $str, MCRYPT_MODE_CBC,$iv));
		return $encrypted_string;
	}
开发者ID:royalwang,项目名称:saivi,代码行数:7,代码来源:Router.class.php

示例15: Template

 function Template($Type)
 {
     global $Bot;
     switch ($Type) {
         case BLOB_ABOUT:
             $this->AddText("SellBot is a bot developed by Demerzel (RK1: Scottish, RK2: Toxor) ");
             $this->AddText("designed to enable people to easily create their own personal shop screen. ");
             $this->AddText("A link to their shop is posted to their selected channel at a specified ");
             $this->AddText("interval of over five minutes; viewers of the shop can then place offers ");
             $this->AddText("or reserve items. Auction functions will become available in future versions.<br><br>");
             $this->AddText("To download SellBot to use for your own shop, visit: <br>");
             $this->AddChatCmd("/start http://code.google.com/p/sellbot/", "http://code.google.com/p/sellbot/");
             $this->Render();
             break;
         case BLOB_OPTIONS:
             $this->Title = "Options";
             $this->AddText("To select the channel your shop will be posted on: ");
             $this->AddChatCmd("/tell " . $Bot->ShopCharacter . " ChanSelect");
             $this->Render();
             break;
         case BLOB_CHOOSECHAN:
             $this->Title = "here.";
             $this->AddText("Here is a list of all the channels your SellBot can send messages to. Click the one on which you want your shop posted.<br>");
             foreach ($Bot->ChatGroups as $GroupId => $Group) {
                 if (substr(bin2hex($Group[0]), 0, 2) == 86) {
                     $this->AddChatCmd("/tell " . $Bot->ShopCharacter . " ChanSelect " . $GroupId, $Group[1]);
                     $this->AddLineBreak();
                 }
             }
             $this->Render();
             break;
         default:
             $this->Title = "[err: unrecognised blob type {$Type}]";
     }
 }
开发者ID:googlecode-mirror,项目名称:sellbot,代码行数:35,代码来源:ChatBlobClass.php


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