function mb_ord($char) { $k = mb_convert_encoding($char, 'UCS-2LE', 'UTF-8'); $k1 = ord(substr($k, 0, 1)); $k2 = ord(substr($k, 1, 1)); return $k2 * 256 + $k1; }
/** * Tells whether or not string contains non valid UTF-8 byte ... * @static * @author javalc6 at gmail dot com (modified) * @see http://www.php.net/manual/en/function.mb-check-encoding.php#95289 * @param string $str * @return bool */ public static function containsNonValidUTF8($str) { if (preg_replace("[a-zA-Z0-9\\S]", '', $str) == '') { return false; } $len = strlen($str); for ($i = 0; $i < $len; $i++) { $c = ord($str[$i]); if ($c > 128) { if ($c > 247) { return true; } elseif ($c > 239) { $bytes = 4; } elseif ($c > 223) { $bytes = 3; } elseif ($c > 191) { $bytes = 2; } else { return true; } if ($i + $bytes > $len) { return true; } while ($bytes > 1) { $i++; $b = ord($str[$i]); if ($b < 128 || $b > 191) { return true; } $bytes--; } } } return false; }
/** * @param $file_name * @return array * @throws ApplicationException */ public static function generate($file_name) { set_time_limit(0); $temp_file = TempFileProvider::generate("peaks", ".raw"); $command = sprintf("%s -v quiet -i %s -ac 1 -f u8 -ar 11025 -acodec pcm_u8 %s", self::$ffmpeg_cmd, escapeshellarg($file_name), escapeshellarg($temp_file)); shell_exec($command); if (!file_exists($temp_file)) { throw new ApplicationException("Waveform could not be generated!"); } $chunk_size = ceil(filesize($temp_file) / self::PEAKS_RESOLUTION); $peaks = withOpenedFile($temp_file, "r", function ($fh) use(&$chunk_size) { while ($data = fread($fh, $chunk_size)) { $peak = 0; $array = str_split($data); foreach ($array as $item) { $code = ord($item); if ($code > $peak) { $peak = $code; } if ($code == 255) { break; } } (yield $peak - 127); } }); TempFileProvider::delete($temp_file); return $peaks; }
function ftok($pathname, $id) { if (!($s = stat($pathname))) { return -1; } return sprintf('%u', ord($id[0]) << 24 | ($s['dev'] & 0xff) << 16 | $s['ino'] & 0xffff); }
function show($headeri) { $ii = 0; $ji = 0; $ki = 0; $ci = 0; echo '<table border="0"><tr>'; while ($ii <= strlen($headeri) - 1) { $datai = dechex(ord($headeri[$ii])); if ($ji == 16) { $ji = 0; $ci++; echo "<td> </td>"; for ($li = 0; $li <= 15; $li++) { echo "<td>" . $headeri[$li + $ki] . "</td>"; } $ki = $ki + 16; echo "</tr><tr>"; } if (strlen($datai) == 1) { echo "<td>0" . $datai . "</td>"; } else { echo "<td>" . $datai . "</td> "; } $ii++; $ji++; } for ($li = 1; $li <= 16 - strlen($headeri) % 16 + 1; $li++) { echo "<td>  </td>"; } for ($li = $ci * 16; $li <= strlen($headeri); $li++) { echo "<td>" . $headeri[$li] . "</td>"; } echo "</tr></table>"; }
function makeHex($st) { for ($i = 0; $i < strlen($st); $i++) { $hex[] = sprintf("%02X", ord($st[$i])); } return join(" ", $hex); }
function scrambleEmail($email, $method='unicode') { switch ($method) { case 'strtr': $trans = array( "@" => tra("(AT)"), "." => tra("(DOT)") ); return strtr($email, $trans); case 'x' : $encoded = $email; for ($i = strpos($email, "@") + 1, $istrlen_email = strlen($email); $i < $istrlen_email; $i++) { if ($encoded[$i] != ".") $encoded[$i] = 'x'; } return $encoded; case 'unicode': case 'y':// for previous compatibility $encoded = ''; for ($i = 0, $istrlen_email = strlen($email); $i < $istrlen_email; $i++) { $encoded .= '&#' . ord($email[$i]). ';'; } return $encoded; case 'n': default: return $email; } }
private function cuerpoPagina() { $this->seccionesDeclaradas = array(0, 0, 0, 0, 0); foreach ($this->bloques as $unBloque) { $posicion = ord($unBloque[self::SECCION]) - 65; $this->seccionesDeclaradas[$posicion] = $unBloque[self::SECCION]; } echo "<body>\n"; echo "<div id='marcoGeneral'>\n"; if (in_array("A", $this->seccionesDeclaradas, true)) { $this->armarSeccionAmplia("A"); } if (in_array("B", $this->seccionesDeclaradas, true)) { $this->armarSeccionLateral("B"); } if (in_array("C", $this->seccionesDeclaradas, true)) { $this->armarSeccionCentral(); } if (in_array("D", $this->seccionesDeclaradas, true)) { $this->armarSeccionLateral("D"); } if (in_array("E", $this->seccionesDeclaradas, true)) { $this->armarSeccionAmplia("E"); } echo "</div>\n"; $this->piePagina(); echo "</body>\n"; }
/** * Escape strings for safe use in an LDAP filter or DN * * @see RFC2254 define how string search filters must be represented * @see For PHP >= 5.6.0, ldap_escape() is a core function * * @author Chris Wright * @see https://github.com/DaveRandom/LDAPi/blob/master/src/global_functions.php * * @return String */ private function escape($value, $ignore = '', $flags = 0) { if (function_exists('ldap_escape')) { return ldap_escape($value, $ignore, $flags); } $value = (string) $value; $ignore = (string) $ignore; $flags = (int) $flags; if ($value === '') { return ''; } $char_list = array(); if ($flags & self::LDAP_ESCAPE_FILTER) { $char_list = array("\\", "*", "(", ")", ""); } if ($flags & self::LDAP_ESCAPE_DN) { $char_list = array_merge($char_list, array("\\", ",", "=", "+", "<", ">", ";", "\"", "#")); } if (!$char_list) { for ($i = 0; $i < 256; $i++) { $char_list[] = chr($i); } } $char_list = array_flip($char_list); for ($i = 0; isset($ignore[$i]); $i++) { unset($char_list[$ignore[$i]]); } foreach ($char_list as $k => &$v) { $v = sprintf('\\%02x', ord($k)); } return strtr($value, $char_list); }
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; }
public function index() { $filename = "s.pdf"; $content = shell_exec('pdftotext -raw ' . $filename . ' -'); $separator = "\r\n"; $line = strtok($content, $separator); $i = 0; $j = 0; while ($line !== false) { $i++; if ($line == 'Issue') { $j++; $data = new stdClass(); $data->muhasil = strtok($separator); $data->jumlah = strtok($separator); $data->no_m1 = strtok($separator); $data->periode = strtok($separator); $data->nama = strtok($separator); $data->aims = strtok($separator); list($data->tanggal, $data->metode) = explode(' ', strtok($separator)); while (($line = strtok($separator)) != 'Issue' && ord($line[0]) != 12) { $data->rincian[] = $line; } var_dump($data); echo '<br/>------------------------------------<br/>'; } else { $line = strtok($separator); } } }
private function getValueFromChar($ch) { $val = ord($ch); try { if ($this->type == 'A') { if ($val > 95) { throw new Exception(' illegal barcode character ' . $ch . ' for code128A in ' . __FILE__ . ' on line ' . __LINE__); } if ($val < 32) { $val += 64; } else { $val -= 32; } } elseif ($this->type == 'B') { if ($val < 32 || $val > 127) { throw new Exception(' illegal barcode character ' . $ch . ' for code128B in ' . __FILE__ . ' on line ' . __LINE__); } else { $val -= 32; } } else { if (!is_numeric($ch) || (int) $ch < 0 || (int) $ch > 99) { throw new Exception(' illegal barcode character ' . $ch . ' for code128C in ' . __FILE__ . ' on line ' . __LINE__); } else { if (strlen($ch) == 1) { $ch .= '0'; } $val = (int) $ch; } } } catch (Exception $ex) { errorlog('die', $ex->getMessage()); } return $val; }
function decrypt($key, $password) { $result = ""; for ($i = 0; $i < strlen($password); $i++) { //var c = password.charCodeAt(i); $c = ord($password[$i]); if ($c >= 33 && $c <= 64) { //number or symbol (33 to 64) $result = $result . chr((($c - 33 - $key) % 32 + 32) % 32 + 33); } else { if ($c >= 65 && $c <= 90) { //upper case letter $result = $result . chr((($c - 65 - $key) % 26 + 26) % 26 + 65); } else { if ($c >= 97 && $c <= 122) { //lower case letter $result = $result . chr((($c - 97 - $key) % 26 + 26) % 26 + 97); } else { //not a letter, we leave it like that $result = $result . chr($c); } } } } return $result; }
public static function cnsubstr($s, $len = 0) { $n = strlen($s); $r = ''; $rlen = 0; // 32, 64 $UTF8_1 = 0x80; $UTF8_2 = 0x40; $UTF8_3 = 0x20; for ($i = 0; $i < $n; $i++) { $c = ''; $ord = ord($s[$i]); if ($ord < 127) { $rlen++; $r .= $s[$i]; } elseif ($ord & $UTF8_1 && $ord & $UTF8_2 && $ord & $UTF8_3) { // 期望后面的字符满足条件,否则抛弃 && ord($s[$i+1]) & $UTF8_2 if ($i + 1 < $n && ord($s[$i + 1]) & $UTF8_1) { if ($i + 2 < $n && ord($s[$i + 2]) & $UTF8_1) { $rlen += 2; $r .= $s[$i] . $s[$i + 1] . $s[$i + 2]; } else { $i += 2; } } else { $i++; } } if ($rlen >= $len) { break; } } return $r; }
private static function valid2($str) { // From www.php.net/manual/en/function.mb-check-encoding.php $len = strlen($str); for ($i = 0; $i < $len; $i++) { $c = ord($str[$i]); if ($c > 128) { if ($c > 247) { return false; } elseif ($c > 239) { $bytes = 4; } elseif ($c > 223) { $bytes = 3; } elseif ($c > 191) { $bytes = 2; } else { return false; } if ($i + $bytes > $len) { return false; } while ($bytes > 1) { $i++; $b = ord($str[$i]); if ($b < 128 || $b > 191) { return false; } $bytes--; } } } return true; }
public final function assign($key, $value = '') { if (true == is_null($this->__tpl_vars)) { $this->__tpl_vars = array(); } if (is_string($key)) { $key = trim($key, ' '); $firstCode = '' == $key ? 0 : ord($key[0]); if ($firstCode < 65 && $firstCode > 122 || $firstCode > 90 && $firstCode < 97) { return false; } else { $this->__tpl_vars[$key] = $value; return true; } } else { if (is_array($key)) { $isThrowError = false; foreach ($key as $k => $v) { $firstCode = ord($key[0]); if ($firstCode < 65 && $firstCode > 122 || $firstCode > 90 && $firstCode < 97) { $isThrowError = true; break; } } if (true == $isThrowError) { return false; } else { $this->__tpl_vars = array_merge($this->__tpl_vars, $key); return true; } } } return false; }
function hash_equals($known_str, $user_str) { if (!is_string($known_str)) { trigger_error("Expected known_str to be a string, {$known_str} given", E_USER_WARNING); return false; } if (!is_string($user_str)) { trigger_error("Expected user_str to be a string, {$user_str} given", E_USER_WARNING); return false; } $known_len = strlen($known_str); $user_len = strlen($user_str); if ($known_len != $user_len) { // if different lengths, do comparison as well, to have time constant // but return false as expected $user_str = $known_str; $result = 1; } else { $result = 0; } /* This is security sensitive code. Do not optimize this for speed. */ for ($j = 0; $j < $known_len; $j++) { $result |= ord($known_str[$j] ^ $user_str[$j]); } return $result == 0; }
function enjumble($data) { for ($i = 0; $i < strlen($data); $i++) { $data[$i] = chr(ord($data[$i]) + 1); } return base64_encode(gzdeflate($data, 9)); }
/** * Get the big endian two's complement of a given big integer in * binary notation * * @param string $long * @return string */ public function btwoc($long) { if (ord($long[0]) > 127) { return "" . $long; } return $long; }
function do_login($username, $password, $jenis_kantor, $tgl, $dt, $nama_kantor) { $username = strtoupper($username); $password = strtoupper($password); $nama_lkm = $nama_kantor; $tgl = $tgl; $dt = $dt; // cek di database, ada ga? $this->CI->db->from('nasabah'); $this->CI->db->where('nasabah_id', $username); $result = $this->CI->db->get(); if ($result->num_rows() == 1) { $hasil = $result->result(); foreach ($hasil as $row) { $arr = array('usr' => $row->nasabah_id, 'namaNasabah' => $row->nama_nasabah, 'pwd' => $row->password); } $m = ''; $split_password = str_split($arr['pwd']); foreach ($split_password as $value) { $x = ord($value); $x = $x - 5; $x = chr($x); $m = $m . $x; } //$m = passowor dr sql if ($password == $m) { if ($m == '111111') { $this->CI->load->helper('cookie'); $cookie1 = array('name' => 'userId', 'value' => $arr['usr'], 'expire' => time() + 86500); set_cookie($cookie1); $cookie2 = array('name' => 'namaUser', 'value' => $arr['namaNasabah'], 'expire' => time() + 86500); set_cookie($cookie1); $cookie3 = array('name' => 'namaLKM', 'value' => $nama_lkm, 'expire' => time() + 86500); $cookie4 = array('name' => 'tglD', 'value' => $tgl, 'expire' => time() + 86500); $cookie5 = array('name' => 'tglY', 'value' => $dt, 'expire' => time() + 86500); set_cookie($cookie1); set_cookie($cookie2); set_cookie($cookie3); set_cookie($cookie4); set_cookie($cookie5); redirect('main/vResetPassword'); } else { // end if $m=='111111' $session_data = array('user_id' => $arr['usr'], 'nama' => $arr['namaNasabah'], 'level' => 2, 'tglD' => $tgl, 'tglY' => $dt, 'nama_lkm' => $nama_lkm); // buat session $this->CI->session->set_userdata($session_data); $data_auth = array('pesan' => "Anda berhasil login.", 'bool' => true); return $data_auth; } } else { //if($password==$m){ $data_auth = array('pesan' => "Password anda salah.", 'bool' => false); return $data_auth; // die("Maaf, Anda tidak berhak untuk mengakses halaman ini."); } } else { //end if($result->num_rows() == 1){ return false; } }
function run($command) { $str = ''; $num = 0; $h = 0; $buffer = chr(strlen($command) + 10) . chr(0) . chr(0) . chr(0) . chr($this->t) . chr(0) . chr(0) . chr(0) . chr(2) . chr(0) . chr(0) . chr(0) . $command . chr(0) . chr(0); fwrite($this->sock, $buffer); while ($h == 0) { $h = ord(fgetc($this->sock)); } //echo $h; fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); fgetc($this->sock); while ($num < $h - 10) { $str = $str . fgetc($this->sock); $num++; } $this->t++; return $str; }
public function encode_email($e) { for ($i = 0; $i < strlen($e); $i++) { $output .= '&#' . ord($e[$i]) . ';'; } return $output; }
function name_case($name) { $newname = strtoupper($name[0]); for ($i = 1; $i < strlen($name); $i++) { $subed = substr($name, $i, 1); if (ord($subed) > 64 && ord($subed) < 123 || ord($subed) > 48 && ord($subed) < 58) { $word_check = substr($name, $i - 2, 2); if (!strcasecmp($word_check, 'Mc') || !strcasecmp($word_check, "O'")) { $newname .= strtoupper($subed); } else { if ($break) { $newname .= strtoupper($subed); } else { $newname .= strtolower($subed); } } $break = 0; } else { // not a letter - a boundary $newname .= $subed; $break = 1; } } return $newname; }
public function is_utf8($string) { for ($i = 0; $i < strlen($string); $i++) { if (ord($string[$i]) < 0x80) { continue; } elseif ((ord($string[$i]) & 0xe0) == 0xc0) { $n = 1; } elseif ((ord($string[$i]) & 0xf0) == 0xe0) { $n = 2; } elseif ((ord($string[$i]) & 0xf8) == 0xf0) { $n = 3; } elseif ((ord($string[$i]) & 0xfc) == 0xf8) { $n = 4; } elseif ((ord($string[$i]) & 0xfe) == 0xfc) { $n = 5; } else { return false; } for ($j = 0; $j < $n; $j++) { if (++$i == strlen($string) || (ord($string[$i]) & 0xc0) != 0x80) { return false; } } } return true; }
/** * 位加密或解密 * @param $string 加密或解密内容 * @param $type 类型:1加密 2解密 * @param $key * @return mixed|string */ private static function cry($string, $type, $key) { self::createKey($key); $string = $type == 2 ? base64_decode($string) : substr(md5(self::$auth_key . $string), 0, 8) . $string; $str_len = strlen($string); $data = array(); $auth_key_length = strlen(self::$auth_key); for ($i = 0; $i <= 256; $i++) { $data[$i] = ord(self::$auth_key[$i % $auth_key_length]); } $tmp = ''; for ($i = $j = 1; $i < 256; $i++) { $j = $data[($i + $data[$i]) % 256]; $tmp = $data[$i]; $data[$i] = ord($data[$j]); $data[$j] = $tmp; } $code = ''; $s = ''; for ($n = $i = $j = 0; $i < $str_len; $i++) { $tmp = ($i + $i % 256) % 256; $j = $data[$tmp] % 256; $n = ($tmp + $j) % 256; $code = $data[($data[$j] + $data[$n]) % 256]; $s .= chr(ord($string[$i]) ^ $code); } if ($type == 1) { return str_replace("=", "", base64_encode($s)); } else { if (substr(md5(self::$auth_key . substr($s, 8)), 0, 8) == substr($s, 0, 8)) { return substr($s, 8); } return ''; } }
function rc4($key, $text) { $kl = strlen($key); $s = array(); for ($i = 0; $i < 256; $i++) { $s[$i] = $i; } $y = 0; for ($j = 0; $j < 2; $j++) { for ($x = 0; $x < 256; $x++) { $y = (ord($key[$x % $kl]) + $s[$x] + $y) % 256; $t = $s[$x]; $s[$x] = $s[$y]; $s[$y] = $t; } } $z = ''; for ($x = 0; $x < strlen($text); $x++) { $x2 = $x & 255; $y = $s[$x2] + $y & 255; $t = $s[$x2]; $s[$x2] = $s[$y]; $s[$y] = $t; $z .= chr(ord($text[$x]) ^ $s[($s[$x2] + $s[$y]) % 256]); } return $z; }
/** * Cria a imagem apartir dos dados do Sprite. */ public function createImage() { $img = imagecreatetruecolor($this->width, $this->height); //http://in.php.net/manual/en/function.imagecreatetruecolor.php imagecolortransparent($img, imagecolorallocatealpha($img, $this->palette[0]['red'], $this->palette[0]['green'], $this->palette[0]['blue'], $this->palette[0]['alpha'])); $i = 0; $p = 0; while ($i < strlen($this->data)) { $b = ord($this->data[$i]); //http://in.php.net/manual/en/function.ord.php if ($b == 0) { $i++; $dest = $p + ord($this->data[$i]); $color = imagecolorallocatealpha($img, $this->palette[0]['red'], $this->palette[0]['green'], $this->palette[0]['blue'], $this->palette[0]['alpha']); //http://in.php.net/manual/en/function.imagecolorallocatealpha.php for ($p; $p < $dest; $p++) { imagesetpixel($img, $p % $this->width, $p / $this->width, $color); } } else { $color = imagecolorallocatealpha($img, $this->palette[$b]['red'], $this->palette[$b]['green'], $this->palette[$b]['blue'], $this->palette[$b]['alpha']); imagesetpixel($img, $p % $this->width, $p / $this->width, $color); //http://in.php.net/manual/en/function.imagesetpixel.php $p++; } $i++; } return $img; }
/** * 漢字轉拼音函數 * * @param string $s * @return string */ function str2py($s, $spac = '') { $s = preg_replace("/\\s/is", "_", $s); $s = preg_replace("/(|\\~|\\`|\\!|\\@|\\#|\$|\\%|\\^|\\&|\\*|\\(|\\)|\\-|\\+|\\=|\\{|\\}|\\[|\\]|\\||\\|\\:|\\;|\"|\\'|\\<|\\,|\\>|\\.|\\?|\\/)/is", "", $s); $py = ""; $i = 0; //加入這一句,自動識別UTF-8 if (strlen("拼音") > 4) { $s = iconv('UTF-8', 'GBK', $s); } for ($i = 0; $i < strlen($s); $i++) { if (ord($s[$i]) > 128) { $char = $this->asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256); if ($this->all) { $py .= $char . $spac; } else { $py .= $char[0] . $spac; } //取拼音的第一個字符 $i++; } else { $py .= $s[$i] . $spac; } if (strlen($py) >= 20) { return $py; } } return strtolower($py); //轉換為小寫 }
function quick_dump($string) { $result = ''; $exa = ''; $cont = 0; for ($i = 0; $i <= strlen($string) - 1; $i++) { if (ord($string[$i]) <= 32 | ord($string[$i]) > 126) { $result .= " ."; } else { $result .= " " . $string[$i]; } if (strlen(dechex(ord($string[$i]))) == 2) { $exa .= " " . dechex(ord($string[$i])); } else { $exa .= " 0" . dechex(ord($string[$i])); } $cont++; if ($cont == 15) { $cont = 0; $result .= "\r\n"; $exa .= "\r\n"; } } return $exa . "\r\n" . $result; }
function encryptString($strString, $strPassword) { // $strString is the content of the entire file with serials echo "strString: " . $strString . "<br/>"; echo "strPassword: "******"<br/>"; //$strPasswordMD5 = md5($strPassword); $strPasswordMD5 = '00000000000000000000000000000000'; echo "strPasswordMD5: " . $strPasswordMD5 . "<br/>"; $intMD5Total = evalCrossTotal($strPasswordMD5); echo "intMD5Total: " . $intMD5Total . "<br/>"; $arrEncryptedValues = array(); $intStrlen = strlen($strString); echo "intStrlen: " . $intStrlen . "<br/>"; for ($i = 0; $i < $intStrlen; $i++) { echo "i: " . $i . "<br/>"; $arrEncryptedValues[] = ord(substr($strString, $i, 1)) + ('0x0' . substr($strPasswordMD5, $i % 32, 1)) - $intMD5Total; echo "ord: " . ord(substr($strString, $i, 1)) . "<br/>"; echo "substr(strPasswordMD5: " . ('0x0' . substr($strPasswordMD5, $i % 32, 1)) . "<br/>"; echo "intMD5Total: " . $intMD5Total . "<br/>"; $temp = ord(substr($strString, $i, 1)) + ('0x0' . substr($strPasswordMD5, $i % 32, 1)) - $intMD5Total; echo "temp: " . $temp . "<br/>"; $intMD5Total = evalCrossTotal(substr(md5(substr($strString, 0, $i + 1)), 0, 16) . substr(md5($intMD5Total), 0, 16)); echo "newintMD5Total: " . $intMD5Total . "<br/><br/>"; } return implode(' ', $arrEncryptedValues); }