本文整理汇总了PHP中Ord函数的典型用法代码示例。如果您正苦于以下问题:PHP Ord函数的具体用法?PHP Ord怎么用?PHP Ord使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Ord函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trim_text
function trim_text($str, $len, $tail = "..")
{
if (strlen($str) < $len) {
return $str;
//자를길이보다 문자열이 작으면 그냥 리턴
} else {
$result_str = '';
for ($i = 0; $i < $len; $i++) {
if (Ord($str[$i]) <= 127 && Ord($str[$i]) >= 0) {
$result_str .= $str[$i];
} else {
if (Ord($str[$i]) <= 223 && Ord($str[$i]) >= 194) {
$result_str .= $str[$i] . $str[$i + 1];
$i + 1;
} else {
if (Ord($str[$i]) <= 239 && Ord($str[$i]) >= 224) {
$result_str .= $str[$i] . $str[$i + 1] . $str[$i + 2];
$i + 2;
} else {
if (Ord($str[$i]) <= 244 && Ord($str[$i]) >= 240) {
$result_str .= $str[$i] . $str[$i + 1] . $str[$i + 2] . $str[$i + 3];
$i + 3;
}
}
}
}
}
return $result_str . $tail;
}
}
示例2: execute
public function execute(&$value, &$error)
{
$cuit = $value;
$coeficiente = array(5, 4, 3, 2, 7, 6, 5, 4, 3, 2);
$cuit_rearmado = "";
//separo cualquier caracter que no tenga que ver con numeros
for ($i = 0; $i < strlen($cuit); $i = $i + 1) {
if (Ord(substr($cuit, $i, 1)) >= 48 && Ord(substr($cuit, $i, 1)) <= 57) {
$cuit_rearmado = $cuit_rearmado . substr($cuit, $i, 1);
}
}
// si no estan todos los digitos
if (strlen($cuit_rearmado) != 11) {
$error = $this->getParameterHolder()->get('cuit_error');
return false;
} else {
$sumador = 0;
$verificador = substr($cuit_rearmado, 10, 1);
//tomo el digito verificador
for ($i = 0; $i <= 9; $i = $i + 1) {
$sumador = $sumador + substr($cuit_rearmado, $i, 1) * $coeficiente[$i];
}
//separo cada digito y lo multiplico por el coeficiente
$resultado = $sumador % 11;
$resultado = 11 - $resultado;
//saco el digito verificador
if (intval($verificador) != $resultado) {
$error = $this->getParameterHolder()->get('cuit_error');
return false;
} else {
//$cuit_rearmado = substr($cuit_rearmado, 0, 2) . "-" . substr($cuit_rearmado, 2, 8) . "-" . substr($cuit_rearmado, 10, 1);
return true;
}
}
}
示例3: escapedata
function escapedata($data)
{
$position = 0;
$length = strlen($data);
$escapeddata = "";
for (; $position < $length;) {
$character = substr($data, $position, 1);
$code = Ord($character);
switch ($code) {
case 34:
$character = """;
break;
case 38:
$character = "&";
break;
case 39:
$character = "'";
break;
case 60:
$character = "<";
break;
case 62:
$character = ">";
break;
default:
if ($code < 32) {
$character = "&#" . strval($code) . ";";
}
break;
}
$escapeddata .= $character;
$position++;
}
return $escapeddata;
}
示例4: VireZeroTerminaux
function VireZeroTerminaux($input)
{
for ($i = 0; $i < strlen($input); $i++) {
if (Ord($input[$i]) == 0) {
$input = substr($input, 0, $i);
return $input;
break;
}
}
}
示例5: adler32
function adler32($adler, $str)
{
$BASE = 65521;
$s1 = $adler & 0xffff;
$s2 = $adler >> 16 & 0xffff;
for ($i = 0; $i < strlen($str); $i++) {
$s1 = ($s1 + Ord($str[$i])) % $BASE;
$s2 = ($s2 + $s1) % $BASE;
}
return $this->leftshift($s2, 16) + $s1;
}
示例6: adler32
function adler32($adler, $str)
{
$BASE = 65521;
$s1 = $adler & 0xffff;
$s2 = $adler >> 16 & 0xffff;
for ($i = 0; $i < strlen($str); $i++) {
$s1 = ($s1 + Ord($str[$i])) % $BASE;
$s2 = ($s2 + $s1) % $BASE;
//echo "s1 : $s1 <BR> s2 : $s2 <BR>";
}
return leftshift($s2, 16) + $s1;
}
示例7: cutString
/**
* 截取字符串(1个汉字长度计为1;1个字母长度计为0.5)
*/
public static function cutString($sourcestr, $cutlength, $addpoint = 1)
{
$returnstr = '';
$i = 0;
$n = 0;
$str_length = strlen($sourcestr);
//字符串的字节数
while ($n < $cutlength and $i <= $str_length) {
$temp_str = substr($sourcestr, $i, 1);
$ascnum = Ord($temp_str);
//得到字符串中第$i位字符的ascii码
if ($ascnum >= 224) {
//如果ASCII位高与224,
$returnstr = $returnstr . substr($sourcestr, $i, 3);
//根据UTF-8编码规范,将3个连续的字符计为单个字符
$i = $i + 3;
//实际Byte计为3
$n++;
//字串长度计1
} elseif ($ascnum >= 192) {
//如果ASCII位高与192,
$returnstr = $returnstr . substr($sourcestr, $i, 2);
//根据UTF-8编码规范,将2个连续的字符计为单个字符
$i = $i + 2;
//实际Byte计为2
$n++;
//字串长度计1
} elseif ($ascnum >= 65 && $ascnum <= 90) {
//如果是大写字母,
$returnstr = $returnstr . substr($sourcestr, $i, 1);
$i = $i + 1;
//实际的Byte数仍计1个
$n++;
//但考虑整体美观,大写字母计成一个高位字符
} else {
//其他情况下,包括小写字母和半角标点符号,
$returnstr = $returnstr . substr($sourcestr, $i, 1);
$i = $i + 1;
//实际的Byte数计1个
$n = $n + 0.5;
//小写字母和半角标点等与半个高位字符宽...
}
}
if ($str_length > $i && $addpoint) {
$returnstr = $returnstr . "...";
//超过长度时在尾处加上省略号
}
return $returnstr;
}
示例8: cn_substr_utf8
function cn_substr_utf8($sourcestr, $cutlength, $cutstart = 0, $isadd = false)
{
$returnstr = '';
$i = 0;
$n = 0;
$str_length = strlen($sourcestr);
//字符串的字节数
while ($n < $cutlength and $i <= $str_length) {
$temp_str = substr($sourcestr, $i, 1);
$ascnum = Ord($temp_str);
//得到字符串中第$i位字符的ascii码
if ($ascnum >= 224) {
$returnstr = $returnstr . substr($sourcestr, $i, 3);
//根据UTF-8编码规范,将3个连续的字符计为单个字符
$i = $i + 3;
//实际Byte计为3
$n++;
//字串长度计1
} elseif ($ascnum >= 192) {
$returnstr = $returnstr . substr($sourcestr, $i, 2);
//根据UTF-8编码规范,将2个连续的字符计为单个字符
$i = $i + 2;
//实际Byte计为2
$n++;
//字串长度计1
} elseif ($ascnum >= 65 && $ascnum <= 90) {
$returnstr = $returnstr . substr($sourcestr, $i, 1);
$i = $i + 1;
//实际的Byte数仍计1个
$n++;
//但考虑整体美观,大写字母计成一个高位字符
} else {
$returnstr = $returnstr . substr($sourcestr, $i, 1);
$i = $i + 1;
//实际的Byte数计1个
//$n = $n + 0.5; //小写字母和半角标点等与半个高位字符宽...
$n = $n + 1;
}
}
if ($isadd) {
if ($str_length > $i) {
$returnstr = $returnstr . "...";
//超过长度时在尾处加上省略号
}
}
return $returnstr;
}
示例9: first
function first()
{
$sourcestr = $this->s;
$returnstr = '';
$i = 0;
$n = 0;
$str_length = strlen($sourcestr);
//字符串的字节数
while ($i <= $str_length) {
$temp_str = substr($sourcestr, $i, 1);
$ascnum = Ord($temp_str);
//得到字符串中第$i位字符的ascii码
if ($ascnum >= 224) {
//如果ASCII位高与224,
$returnstr = $returnstr . $this->getHanziInitial(substr($sourcestr, $i, 3));
//根据UTF-8编码规范,将3个连续的字符计为单个字符
$i = $i + 3;
//实际Byte计为3
} else {
if ($ascnum >= 192) {
//如果ASCII位高与192,
$returnstr = $returnstr . $this->getHanziInitial(substr($sourcestr, $i, 2));
//根据UTF-8编码规范,将2个连续的字符计为单个字符
$i = $i + 2;
//实际Byte计为2
} else {
if ($ascnum >= 65 && $ascnum <= 90) {
//如果是大写字母,
$returnstr = $returnstr . substr($sourcestr, $i, 1);
$i = $i + 1;
//实际的Byte数仍计1个
} else {
//其他情况下,包括小写字母和半角标点符号,
$returnstr = $returnstr . strtoupper(substr($sourcestr, $i, 1));
//小写字母转换为大写
$i = $i + 1;
//实际的Byte数计1个
}
}
}
}
return strtolower($returnstr);
}
示例10: validateAttribute
protected function validateAttribute($object, $attribute)
{
// Cuit que proviene como parametro
$cuit = $object->{$attribute};
$esCuit = false;
$cuit_rearmado = "";
//separo cualquier caracter que no tenga que ver con numeros
for ($i = 0; $i < strlen($cuit); $i++) {
if (Ord(substr($cuit, $i, 1)) >= 48 && Ord(substr($cuit, $i, 1)) <= 57) {
$cuit_rearmado = $cuit_rearmado . substr($cuit, $i, 1);
}
}
$cuit = $cuit_rearmado;
if (strlen($cuit_rearmado) != 11) {
// si to estan todos los digitos
$esCuit = false;
} else {
$x = $i = $dv = 0;
// Multiplico los dígitos.
$vec[0] = substr($cuit, 0, 1) * 5;
$vec[1] = substr($cuit, 1, 1) * 4;
$vec[2] = substr($cuit, 2, 1) * 3;
$vec[3] = substr($cuit, 3, 1) * 2;
$vec[4] = substr($cuit, 4, 1) * 7;
$vec[5] = substr($cuit, 5, 1) * 6;
$vec[6] = substr($cuit, 6, 1) * 5;
$vec[7] = substr($cuit, 7, 1) * 4;
$vec[8] = substr($cuit, 8, 1) * 3;
$vec[9] = substr($cuit, 9, 1) * 2;
// Suma cada uno de los resultado.
for ($i = 0; $i <= 9; $i++) {
$x += $vec[$i];
}
$dv = (11 - $x % 11) % 11;
if ($dv == substr($cuit, 10, 1)) {
$esCuit = true;
}
}
// Error
if (!$esCuit) {
$this->addError($object, $attribute, Yii::t('app', 'CUIT inválida'));
}
}
示例11: cut_str
/**
* 切割字符串
*/
function cut_str($sourcestr, $cutlength)
{
//对函数参数进行安全保护
/*
$sourcestr参数无需要保护,只要是字符串都可以,
$cutlength参数要求为整数
*/
if (!ctype_digit($cutlength) || empty($cutlength)) {
$cutlength = intval($cutlength);
}
//强制让第二个参数为数字
if (!$cutlength) {
return $sourcestr;
}
//如果长度为0或者空,直接返回整个字符串
$returnstr = '';
$i = 0;
$n = 0;
$str_length = strlen($sourcestr);
while ($n < $cutlength and $i <= $str_length) {
$temp_str = substr($sourcestr, $i, 1);
$ascnum = Ord($temp_str);
if ($ascnum >= 224) {
$returnstr = $returnstr . substr($sourcestr, $i, 3);
$i = $i + 3;
$n++;
} elseif ($ascnum >= 192) {
$returnstr = $returnstr . substr($sourcestr, $i, 2);
$i = $i + 2;
$n++;
} elseif ($ascnum >= 65 && $ascnum <= 90) {
$returnstr = $returnstr . substr($sourcestr, $i, 1);
$i = $i + 1;
$n++;
} else {
$returnstr = $returnstr . substr($sourcestr, $i, 1);
$i = $i + 1;
$n = $n + 0.5;
}
}
return $returnstr;
}
示例12: titlen
function titlen($title, $titlelen)
{
$len = strlen($title);
if ($len <= $titlelen) {
$title1 = $title;
} else {
$title1 = substr($title, 0, $titlelen);
$parity = 0;
for ($i = 0; $i < $titlelen; $i++) {
$temp_str = substr($title, $i, 1);
if (Ord($temp_str) > 127) {
$parity += 1;
}
}
if ($parity % 2 == 1) {
$title1 = substr($title, 0, $titlelen - 1) . "...";
} else {
$title1 = substr($title, 0, $titlelen) . "...";
}
}
return $title1;
}
示例13: cutStr
public static function cutStr($sourceStr, $cutLength = 10, $extStr = '...')
{
$returnStr = '';
$i = 0;
$n = 0;
$strLength = strlen($sourceStr);
if ($strLength > $cutLength) {
while ($n < $cutLength and $i <= $strLength) {
$tempStr = substr($sourceStr, $i, 1);
$ascnum = Ord($tempStr);
if ($ascnum >= 224) {
$returnStr = $returnStr . substr($sourceStr, $i, 3);
$i = $i + 3;
$n++;
} elseif ($ascnum >= 192) {
$returnStr = $returnStr . substr($sourceStr, $i, 2);
$i = $i + 2;
$n++;
} elseif ($ascnum >= 65 && $ascnum <= 90) {
$returnStr = $returnStr . substr($sourceStr, $i, 1);
$i = $i + 1;
$n++;
} else {
$returnStr = $returnStr . substr($sourceStr, $i, 1);
$i = $i + 1;
$n = $n + 0.5;
}
}
if ($strLength > $i) {
$returnStr = $returnStr . $extStr;
}
return $returnStr;
} else {
return $sourceStr;
}
}
示例14: CollapsePhoneNumber
function CollapsePhoneNumber($sPhoneNumber, $sPhoneCountry)
{
switch ($sPhoneCountry) {
case "United States":
$sCollapsedPhoneNumber = "";
$bHasExtension = false;
// Loop through the input string
for ($iCount = 0; $iCount <= strlen($sPhoneNumber); $iCount++) {
// Take one character...
$sThisCharacter = substr($sPhoneNumber, $iCount, 1);
// Is it a number?
if (Ord($sThisCharacter) >= 48 && Ord($sThisCharacter) <= 57) {
// Yes, add it to the returned value.
$sCollapsedPhoneNumber .= $sThisCharacter;
} else {
if (!$bHasExtension && ($sThisCharacter == "e" || $sThisCharacter == "E")) {
// Yes, add the extension identifier 'e' to the stored string.
$sCollapsedPhoneNumber .= "e";
// From now on, ignore other non-digits and process normally
$bHasExtension = true;
}
}
}
break;
default:
$sCollapsedPhoneNumber = $sPhoneNumber;
break;
}
return $sCollapsedPhoneNumber;
}
示例15: ReadCentralDir
function ReadCentralDir($zip, $zip_name)
{
$size = filesize($zip_name);
if ($size < 277) {
$maximum_size = $size;
} else {
$maximum_size = 277;
}
@fseek($zip, $size - $maximum_size);
$pos = ftell($zip);
$bytes = 0x0;
while ($pos < $size) {
$byte = @fread($zip, 1);
$bytes = $bytes << 8 & 4294967295.0 | Ord($byte);
if ($bytes == 0x504b0506) {
$pos++;
break;
}
$pos++;
}
$data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', fread($zip, 18));
if ($data['comment_size'] != 0) {
$centd['comment'] = fread($zip, $data['comment_size']);
} else {
$centd['comment'] = '';
}
$centd['entries'] = $data['entries'];
$centd['disk_entries'] = $data['disk_entries'];
$centd['offset'] = $data['offset'];
$centd['disk_start'] = $data['disk_start'];
$centd['size'] = $data['size'];
$centd['disk'] = $data['disk'];
return $centd;
}