本文整理汇总了PHP中base_convert函数的典型用法代码示例。如果您正苦于以下问题:PHP base_convert函数的具体用法?PHP base_convert怎么用?PHP base_convert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了base_convert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/** Creates directory or throws exception on fail
* @param string $pathname
* @param int $mode Mode in octal
* @return bool
*/
public static function create($pathname, $mode = self::MOD_DEFAULT)
{
if (strpos($pathname, '/') !== false) {
$pathname = explode('/', $pathname);
}
if (is_array($pathname)) {
$current_dir = '';
$create = array();
do {
$current_dir = implode('/', $pathname);
if (is_dir($current_dir)) {
break;
}
$create[] = array_pop($pathname);
} while (any($pathname));
if (any($create)) {
$create = array_reverse($create);
$current_dir = implode('/', $pathname);
foreach ($create as $dir) {
$current_dir .= '/' . $dir;
if (!is_dir($current_dir)) {
if (!($action = @mkdir($current_dir, $mode))) {
throw new \System\Error\Permissions(sprintf('Failed to create directory on path "%s" in mode "%s". Please check your permissions.', $current_dir, base_convert($mode, 10, 8)));
}
}
}
}
} else {
if (!($action = @mkdir($pathname, $mode, true))) {
throw new \System\Error\Permissions(sprintf('Failed to create directory on path "%s" in mode "%s". Please check your permissions.', $pathname, base_convert($mode, 10, 8)));
}
}
return $action;
}
示例2: load
public function load(ObjectManager $manager)
{
// Obtener todas las ciudades de la base de datos
$ciudades = $manager->getRepository('CiudadBundle:Ciudad')->findAll();
$i = 1;
foreach ($ciudades as $ciudad) {
$numeroTiendas = rand(2, 5);
for ($j = 1; $j <= $numeroTiendas; $j++) {
$tienda = new Tienda();
$tienda->setNombre($this->getNombre());
$tienda->setLogin('tienda' . $i);
$tienda->setSalt(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36));
$passwordEnClaro = 'tienda' . $i;
$encoder = $this->container->get('security.encoder_factory')->getEncoder($tienda);
$passwordCodificado = $encoder->encodePassword($passwordEnClaro, $tienda->getSalt());
$tienda->setPassword($passwordCodificado);
$tienda->setDescripcion($this->getDescripcion());
$tienda->setDireccion($this->getDireccion($ciudad));
$tienda->setCiudad($ciudad);
$manager->persist($tienda);
$i++;
}
}
$manager->flush();
}
示例3: twofactor_genkey
/**
* Generate Secret Key
* @return string
*/
function twofactor_genkey()
{
global $base32_enc;
// RFC 4226 recommends 160bits Secret Keys, that's 20 Bytes for the lazy ones.
$crypto = false;
$raw = "";
$x = -1;
while ($crypto == false || ++$x < 10) {
$raw = openssl_random_pseudo_bytes(20, $crypto);
}
// RFC 4648 Base32 Encoding without padding
$len = strlen($raw);
$bin = "";
$x = -1;
while (++$x < $len) {
$bin .= str_pad(base_convert(ord($raw[$x]), 10, 2), 8, '0', STR_PAD_LEFT);
}
$bin = str_split($bin, 5);
$ret = "";
$x = -1;
while (++$x < sizeof($bin)) {
$ret .= $base32_enc[base_convert(str_pad($bin[$x], 5, '0'), 2, 10)];
}
return $ret;
}
示例4: decode
public static function decode($input)
{
if (empty($input)) {
return;
}
$paddingCharCount = substr_count($input, self::$map[32]);
$allowedValues = array(6, 4, 3, 1, 0);
if (!in_array($paddingCharCount, $allowedValues)) {
return false;
}
for ($i = 0; $i < 4; $i++) {
if ($paddingCharCount == $allowedValues[$i] && substr($input, -$allowedValues[$i]) != str_repeat(self::$map[32], $allowedValues[$i])) {
return false;
}
}
$input = str_replace('=', '', $input);
$input = str_split($input);
$binaryString = "";
for ($i = 0; $i < count($input); $i = $i + 8) {
$x = "";
if (!in_array($input[$i], self::$map)) {
return false;
}
for ($j = 0; $j < 8; $j++) {
$x .= str_pad(base_convert(@self::$flippedMap[@$input[$i + $j]], 10, 2), 5, '0', STR_PAD_LEFT);
}
$eightBits = str_split($x, 8);
for ($z = 0; $z < count($eightBits); $z++) {
$binaryString .= ($y = chr(base_convert($eightBits[$z], 2, 10))) || ord($y) == 48 ? $y : "";
}
}
return $binaryString;
}
示例5: __construct
/**
* Конструктор
*
* @param mixed $value Число (0xFFEEDD), массив (array(0xFF, 0xEE, 0xDD)), либо строка ('#FFEEDD' или название web-цвета)
*/
function __construct($value)
{
/**
* Если число сохраняем
*/
if (is_int($value)) {
$this->RGB = $value;
} else {
if (is_array($value) && count($value) == 3) {
$temp = array_values($value);
$this->RGB = ($temp[0] & 0xff) << 16 | ($temp[1] & 0xff) << 8 | $temp[2] & 0xff;
} else {
if (is_string($value)) {
if ($value[0] == '#') {
$this->RGB = intval(base_convert(trim($value, '# '), 16, 10)) & 0xffffff;
} else {
if (isset(self::$webColors[$temp = strtolower($value)])) {
$this->RGB = self::$webColors[$temp];
}
}
}
}
}
/**
* Иначе выдаём ошибку
*/
if ($this->RGB === FALSE) {
triggerError(sprintf(Open_Text::getInstance()->dget('errors', 'The value "<b>%s</b>" cannot be converted to color'), $value), E_USER_WARNING);
}
}
示例6: hex2arr
/**
* 递归从左到右处理每一个字节 把非法的字节替换成?
* GBK定义 如果单个字节的第8个BIT是0(高位),則这个字节是一个字符
* 如果是1 则和后面的一个字节合成一个字符,后面的这个字节的第8个BIT也必须是1
* 第二个字节范围 x40 64 xFE 254
* 字符有一字节和双字节编码,00–7F范围内是一位,和ASCII保持一致
* 双字节中,第一字节的范围是81–FE(也就是不含80和FF),第二字节的一部分领域在40–FE
* @access public
* @param mixed $str
* @return void
* @author 刘建辉
* @修改日期 2013-02-21 17:28:28
*/
public static function hex2arr($str)
{
$arr = array();
$i = 0;
$len = strlen($str);
while ($i < $len) {
$firstStr = substr($str, $i, 2);
$firstStrdec = base_convert($firstStr, 16, 10);
if ($firstStrdec > 128 && $firstStrdec < 255) {
//双字节字符
$secondStr = base_convert(substr($str, $i + 2, 2), 16, 10);
if ($secondStr > 63 && $secondStr < 255) {
$arr[] = substr($str, $i, 4);
} else {
$arr[] = '3f';
}
$i += 4;
} else {
//单字节字符
$arr[] = $firstStrdec > 33 && $firstStrdec < 126 ? $firstStr : '3f';
$i += 2;
}
}
return $arr;
}
示例7: login
public function login($username, $password, $hash = true)
{
if (empty($username) || empty($password)) {
return false;
}
if ($hash) {
$password = md5($password);
}
$query = $this->db->query("SELECT `password` FROM `" . DB_PREFIX . "user` WHERE `username` = '" . $this->db->escape($username) . "'");
list($pass, $suffix) = explode(':', $query->row['password']);
if (!$suffix) {
$suffix = md5(base_convert(rand(1.0E+17, 1.0E+21), 10, 36) . time());
$this->db->query("UPDATE `" . DB_PREFIX . "user` SET \n `password` = '" . $this->db->escape(md5($password . $suffix) . ':' . $suffix) . "' \n WHERE `username` = '" . $this->db->escape($username) . "'");
}
$user_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "user` " . "WHERE username = '" . $this->db->escape($username) . "' " . "AND password = '" . $this->db->escape(md5($password . $suffix) . ':' . $suffix) . "'");
if ($user_query->num_rows) {
$this->session->set('user_id', $user_query->row['user_id']);
$utoken = $this->session->has('utoken') ? $this->session->get('utoken') : md5(date('d-m-Y') . mt_rand(1000000000, 9999999999));
$this->session->set('utoken', $utoken);
$this->ukey = md5($this->key) . ":" . $this->session->get('utoken') . "_" . $user_query->row['user_id'];
$this->session->set('token', $this->ukey);
$this->session->set('nttoken', $this->key . $this->session->get('utoken'));
$this->session->set('ukey', $this->ukey);
$this->user_id = $user_query->row['user_id'];
$this->username = $user_query->row['username'];
$user_group_query = $this->db->query("SELECT permission FROM " . DB_PREFIX . "user_group WHERE user_group_id = '" . (int) $user_query->row['user_group_id'] . "'");
foreach (unserialize($user_group_query->row['permission']) as $key => $value) {
$this->permissions[$key] = $value;
}
return true;
} else {
return false;
}
}
示例8: testPerformanceCreateAction
public function testPerformanceCreateAction()
{
$this->request('/admin/Performance/create', 'GET', 302);
$this->request('/admin/Performance/create' . base_convert(md5(uniqid()), 11, 10), 'GET', 404);
$this->logIn();
$this->request('/admin/Performance/create', 'GET', 200);
}
示例9: saveMIDItoFile
public function saveMIDItoFile()
{
$this->filename = base_convert(mt_rand(), 10, 36);
$this->filepath = $this->saveDir.$this->filename;
$this->midi->saveMidFile($this->filepath.'.mid', 0666);
return true;
}
示例10: make_seccode
public static function make_seccode($seccode = '')
{
global $_G;
if (!$seccode) {
$seccode = random(6, 1);
$seccodeunits = '';
if ($_G['setting']['seccodedata']['type'] == 1) {
$lang = lang('seccode');
$len = strtoupper(CHARSET) == 'GBK' ? 2 : 3;
$code = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
$seccode = '';
for ($i = 0; $i < 2; $i++) {
$seccode .= substr($lang['chn'], $code[$i] * $len, $len);
}
} elseif ($_G['setting']['seccodedata']['type'] == 3) {
$s = sprintf('%04s', base_convert($seccode, 10, 20));
$seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ';
} else {
$s = sprintf('%04s', base_convert($seccode, 10, 24));
$seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
}
if ($seccodeunits) {
$seccode = '';
for ($i = 0; $i < 4; $i++) {
$unit = ord($s[$i]);
$seccode .= $unit >= 0x30 && $unit <= 0x39 ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
}
}
}
self::_create('code', $seccode);
return $seccode;
}
示例11: get_subscribed_forum_func
function get_subscribed_forum_func()
{
global $config, $db, $user, $auth, $mobiquo_config, $phpbb_home;
$user->setup('ucp');
if (!$user->data['is_registered']) {
trigger_error('LOGIN_EXPLAIN_UCP');
}
$forum_list = array();
if ($config['allow_forum_notify']) {
$forbidden_forums = $auth->acl_getf('!f_read', true);
$forbidden_forums = array_unique(array_keys($forbidden_forums));
if (isset($mobiquo_config['hide_forum_id'])) {
$forbidden_forums = array_unique(array_merge($forbidden_forums, $mobiquo_config['hide_forum_id']));
}
$sql_array = array('SELECT' => 'f.*', 'FROM' => array(FORUMS_WATCH_TABLE => 'fw', FORUMS_TABLE => 'f'), 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
AND f.forum_id = fw.forum_id
AND ' . $db->sql_in_set('f.forum_id', $forbidden_forums, true, true), 'ORDER_BY' => 'left_id');
if ($config['load_db_lastread']) {
$sql_array['LEFT_JOIN'] = array(array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'));
$sql_array['SELECT'] .= ', ft.mark_time ';
} else {
$tracking_topics = isset($_COOKIE[$config['cookie_name'] . '_track']) ? STRIP ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track'] : '';
$tracking_topics = $tracking_topics ? tracking_unserialize($tracking_topics) : array();
}
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
$forum_list = array();
while ($row = $db->sql_fetchrow($result)) {
$forum_id = $row['forum_id'];
if ($config['load_db_lastread']) {
$forum_check = !empty($row['mark_time']) ? $row['mark_time'] : $user->data['user_lastmark'];
} else {
$forum_check = isset($tracking_topics['f'][$forum_id]) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
}
$unread_forum = $row['forum_last_post_time'] > $forum_check ? true : false;
$logo_url = '';
if (file_exists("./forum_icons/{$forum_id}.png")) {
$logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/{$forum_id}.png";
} else {
if (file_exists("./forum_icons/{$forum_id}.jpg")) {
$logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/{$forum_id}.jpg";
} else {
if (file_exists("./forum_icons/default.png")) {
$logo_url = $phpbb_home . $config['tapatalkdir'] . "/forum_icons/default.png";
} else {
if ($row['forum_image']) {
$logo_url = $phpbb_home . $row['forum_image'];
}
}
}
}
$xmlrpc_forum = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id), 'forum_name' => new xmlrpcval(html_entity_decode($row['forum_name']), 'base64'), 'icon_url' => new xmlrpcval($logo_url), 'is_protected' => new xmlrpcval($row['forum_password'] ? true : false, 'boolean'), 'sub_only' => new xmlrpcval($row['forum_type'] == FORUM_POST ? false : true, 'boolean'), 'new_post' => new xmlrpcval($unread_forum, 'boolean')), 'struct');
$forum_list[] = $xmlrpc_forum;
}
$db->sql_freeresult($result);
}
$forum_num = count($forum_list);
$response = new xmlrpcval(array('total_forums_num' => new xmlrpcval($forum_num, 'int'), 'forums' => new xmlrpcval($forum_list, 'array')), 'struct');
return new xmlrpcresp($response);
}
示例12: doSynlogin
protected function doSynlogin($request, $get, $post)
{
if (!API_SYNLOGIN) {
return API_RETURN_FORBIDDEN;
}
$partnerUser = uc_get_user($get['uid'], 1);
$bind = $this->getUserService()->getUserBindByTypeAndFromId('discuz', $get['uid']);
if (UC_CHARSET == 'gbk') {
$get['username'] = iconv('gb2312', 'UTF-8', $get['username']);
}
if (empty($bind)) {
$registration = array('nickname' => $get['username'], 'email' => $partnerUser[2], 'password' => substr(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36), 0, 8), 'createdTime' => $get['time'], 'createdIp' => $request->getClientIp(), 'token' => array('userId' => $get['uid']));
if (!$this->getAuthService()->isRegisterEnabled()) {
return API_RETURN_FORBIDDEN;
}
$user = $this->getUserService()->register($registration, 'discuz');
} else {
$user = $this->getUserService()->getUser($bind['toId']);
if (empty($user)) {
return API_RETURN_SUCCEED;
}
}
$this->authenticateUser($user);
return API_RETURN_SUCCEED;
}
示例13: generateChecksum
/**
* @param string $input
* @return string
* @throws \InvalidArgumentException
*/
protected function generateChecksum($input)
{
$invalidChars = array();
foreach (str_split($input) as $char) {
if (!in_array($char, $this->characterMap)) {
$invalidChars[] = $char;
}
}
if (count($invalidChars)) {
throw new \InvalidArgumentException("Argument 1 contains the following characters not in the character map: " . implode(" ", $invalidChars));
}
$base = count($this->characterMap);
$factor = 2;
$total = 0;
for ($i = strlen($input) - 1; $i >= 0; $i--) {
$codePoint = array_search(substr($input, $i, 1), $this->characterMap);
$add = base_convert($codePoint * $factor, 10, $base);
if ($add > 9) {
$add = array_sum(str_split($add));
}
$total = $total + $add;
$factor = $factor == 2 ? 1 : 2;
}
return $this->characterMap[$base - $total % $base];
}
示例14: getId
/**
* Get unique identifier
*/
public function getId()
{
if (!isset($this->options['id'])) {
$this->options['id'] = isset($this->options['name']) ? $this->options['name'] . '-form' : base_convert(uniqid(), 16, 36);
}
return $this->options['id'];
}
示例15: generate
/**
* {@inheritdoc}
*/
public function generate()
{
// Obtain a random string of 32 hex characters.
$hex = bin2hex(Crypt::randomBytes(16));
// The variable names $time_low, $time_mid, $time_hi_and_version,
// $clock_seq_hi_and_reserved, $clock_seq_low, and $node correlate to
// the fields defined in RFC 4122 section 4.1.2.
//
// Use characters 0-11 to generate 32-bit $time_low and 16-bit $time_mid.
$time_low = substr($hex, 0, 8);
$time_mid = substr($hex, 8, 4);
// Use characters 12-15 to generate 16-bit $time_hi_and_version.
// The 4 most significant bits are the version number (0100 == 0x4).
// We simply skip character 12 from $hex, and concatenate the strings.
$time_hi_and_version = '4' . substr($hex, 13, 3);
// Use characters 16-17 to generate 8-bit $clock_seq_hi_and_reserved.
// The 2 most significant bits are set to one and zero respectively.
$clock_seq_hi_and_reserved = base_convert(substr($hex, 16, 2), 16, 10);
$clock_seq_hi_and_reserved &= 0b111111;
$clock_seq_hi_and_reserved |= 0b10000000;
// Use characters 18-19 to generate 8-bit $clock_seq_low.
$clock_seq_low = substr($hex, 18, 2);
// Use characters 20-31 to generate 48-bit $node.
$node = substr($hex, 20);
// Re-combine as a UUID. $clock_seq_hi_and_reserved is still an integer.
$uuid = sprintf('%s-%s-%s-%02x%s-%s', $time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $clock_seq_low, $node);
return $uuid;
}