本文整理汇总了PHP中ord函数的典型用法代码示例。如果您正苦于以下问题:PHP ord函数的具体用法?PHP ord怎么用?PHP ord使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ord函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mb_ord
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;
}
示例2: containsNonValidUTF8
/**
* 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;
}
示例3: generate
/**
* @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;
}
示例4: ftok
function ftok($pathname, $id)
{
if (!($s = stat($pathname))) {
return -1;
}
return sprintf('%u', ord($id[0]) << 24 | ($s['dev'] & 0xff) << 16 | $s['ino'] & 0xffff);
}
示例5: show
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>";
}
示例6: makeHex
function makeHex($st)
{
for ($i = 0; $i < strlen($st); $i++) {
$hex[] = sprintf("%02X", ord($st[$i]));
}
return join(" ", $hex);
}
示例7: scrambleEmail
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;
}
}
示例8: cuerpoPagina
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";
}
示例9: escape
/**
* 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);
}
示例10: 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;
}
示例11: index
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);
}
}
}
示例12: getValueFromChar
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;
}
示例13: decrypt
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;
}
示例14: cnsubstr
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;
}
示例15: valid2
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;
}