本文整理汇总了PHP中ctype_cntrl函数的典型用法代码示例。如果您正苦于以下问题:PHP ctype_cntrl函数的具体用法?PHP ctype_cntrl怎么用?PHP ctype_cntrl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ctype_cntrl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hexdump
/**
* Return a hexadecimal dump of the given string
*
* @param string $string
* @return string the hexadecimally formatted output
*/
function hexdump($string)
{
$count = strlen($string);
$dumpo = null;
$dumpo = $count;
$dumpo .= "<br />";
$lineo = "";
$hexo = "";
for ($i = 1; $i <= $count; $i++) {
$ch = $string[$i - 1];
if (ctype_cntrl($ch)) {
$lineo .= ".";
} else {
$lineo .= $ch;
}
$hexo .= bin2hex($ch);
$hexo .= " ";
if (0 == $i % 20) {
$lineo = htmlentities($lineo);
$dumpo .= $lineo . " " . $hexo . "<br />";
$lineo = "";
$hexo = "";
}
}
$dumpo .= htmlentities(substr($lineo . str_repeat(".", 20), 0, 20));
$dumpo .= " ";
$dumpo .= $hexo;
$dumpo .= "<br />";
return $dumpo;
}
示例2: validate
/**
* @inheritdoc
*/
public function validate($input)
{
if (!is_scalar($input) || $input === '') {
return false;
}
$input = str_replace(str_split($this->params['additionalChars']), '', (string) $input);
return $input === '' || ctype_cntrl($input);
}
示例3: validateKey
public function validateKey($key)
{
for ($i = 0; $i < strlen($key); ++$i) {
if (ctype_cntrl($key[$i])) {
throw new \Hoard\InvalidArgumentException("Keys cannot contain control characters.");
}
if (ctype_space($key[$i])) {
throw new \Hoard\InvalidArgumentException("Keys cannot contain whitespace characters.");
}
}
}
示例4: quoted_printable_encode
function quoted_printable_encode($str, $wrap = true)
{
$ret = '';
$l = strLen($str);
$current_locale = setLocale(LC_CTYPE, 0);
setLocale(LC_CTYPE, 'C');
for ($i = 0; $i < $l; ++$i) {
$char = $str[$i];
if (ctype_print($char) && !ctype_cntrl($char) && $char !== '=') {
$ret .= $char;
} else {
$ret .= sPrintF('=%02X', ord($char));
}
}
setLocale(LC_CTYPE, $current_locale);
return $wrap ? wordWrap($ret, 67, " =\n") : $ret;
}
示例5: quoted_printable_encode
function quoted_printable_encode($str)
{
$php_qprint_maxl = 75;
$lp = 0;
$ret = '';
$hex = "0123456789ABCDEF";
$length = strlen($str);
$str_index = 0;
while ($length--) {
if (($c = $str[$str_index++]) == "\r" && $str[$str_index] == "\n" && $length > 0) {
$ret .= "\r";
$ret .= $str[$str_index++];
$length--;
$lp = 0;
} else {
if (ctype_cntrl($c) || ord($c) == 0x7f || ord($c) & 0x80 || $c == '=' || $c == ' ' && $str[$str_index] == "\r") {
if (($lp += 3) > $php_qprint_maxl) {
$ret .= '=';
$ret .= "\r";
$ret .= "\n";
$lp = 3;
}
$ret .= '=';
$ret .= $hex[ord($c) >> 4];
$ret .= $hex[ord($c) & 0xf];
} else {
if (++$lp > $php_qprint_maxl) {
$ret .= '=';
$ret .= "\r";
$ret .= "\n";
$lp = 1;
}
$ret .= $c;
if ($lp == 1 && $c == '.') {
$ret .= '.';
$lp++;
}
}
}
}
return $ret;
}
示例6: ctype_cntrl
<?php
/* Prototype : bool ctype_cntrl(mixed $c)
* Description: Checks for control character(s)
* Source code: ext/ctype/ctype.c
*/
/*
* Pass hexadecimal and octal values to ctype_cntrl() to test behaviour
*/
echo "*** Testing ctype_cntrl() : usage variations ***\n";
$orig = setlocale(LC_CTYPE, "C");
$octal_values = array(01, 02, 03, 04);
$hex_values = array(0x1, 0x2, 0x3, 0x4);
echo "\n-- Octal Values --\n";
$iterator = 1;
foreach ($octal_values as $c) {
echo "-- Iteration {$iterator} --\n";
var_dump(ctype_cntrl($c));
$iterator++;
}
echo "\n-- Hexadecimal Values --\n";
$iterator = 1;
foreach ($hex_values as $c) {
echo "-- Iteration {$iterator} --\n";
var_dump(ctype_cntrl($c));
$iterator++;
}
setlocale(LC_CTYPE, $orig);
?>
===DONE===
示例7: validate
function validate($str, $vtype = NULL, $option = NULL)
{
# check for required fields
if (is_null($vtype)) {
return !empty($str) ? true : false;
}
switch ($vtype) {
case strtolower('alnum'):
return preg_match('/^[a-z0-9 ]*$/i', utf8_decode($str)) ? true : false;
break;
case strtolower('alpha'):
return preg_match('/^[a-z ]*$/i', utf8_decode($str)) ? true : false;
break;
case strtolower('control'):
return ctype_cntrl(utf8_decode($str)) ? true : false;
break;
case strtolower('digit'):
case strtolower('number'):
case strtolower('numeric'):
return preg_match('/^[0-9,.]*$/i', utf8_decode($str)) ? true : false;
break;
case strtolower('graph'):
return ctype_graph(utf8_decode($str)) ? true : false;
break;
case strtolower('lower'):
return ctype_lower(utf8_decode($str)) ? true : false;
break;
case strtolower('print'):
return ctype_print(utf8_decode($str)) ? true : false;
break;
case strtolower('punct'):
case strtolower('punctuation'):
return ctype_punct(utf8_decode($str)) ? true : false;
break;
case strtolower('space'):
case strtolower('whitespace'):
return ctype_space(utf8_decode($str)) ? true : false;
break;
case strtolower('upper'):
return ctype_upper(utf8_decode($str)) ? true : false;
break;
case strtolower('xdigit'):
case strtolower('hexa'):
return ctype_xdigit(utf8_decode($str)) ? true : false;
break;
case strtolower('length'):
# for length
if (is_null($option) || !is_numeric($option)) {
return 'The length is not specified or is invalid in third argument!';
}
return strlen(utf8_decode($str)) > $length ? false : true;
break;
case strtolower('regex'):
# for regex
if (is_null($option)) {
return 'The pattern is not specified or is invalid in third argument!';
}
return preg_match("'" . $option . "'", $str) ? true : false;
break;
case strtolower('email'):
return !preg_match("/^([a-z0-9\\+_\\-]+)(\\.[a-z0-9\\+_\\-]+)*@([a-z0-9\\-]+\\.)+[a-z]{2,6}\$/ix", $str) ? false : true;
break;
case strtolower('string'):
return is_string(utf8_decode($str)) ? true : false;
break;
case strtolower('float'):
return filter_var($str, FILTER_VALIDATE_FLOAT) === true ? true : false;
break;
case strtolower('url'):
case strtolower('web'):
return filter_var($str, FILTER_VALIDATE_URL) === true ? true : false;
break;
case strtolower('ipv4'):
return filter_var($str, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true ? true : false;
break;
case strtolower('ipv6'):
return filter_var($str, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true ? true : false;
break;
default:
print "Invalid Validator Type Specified !!";
exit;
}
}
示例8: ctype_cntrl
<?php
/* Prototype : bool ctype_cntrl(mixed $c)
* Description: Checks for control character(s)
* Source code: ext/ctype/ctype.c
*/
/*
* Pass different integers to ctype_cntrl() to test which character codes are considered
* valid control characters
*/
echo "*** Testing ctype_cntrl() : usage variations ***\n";
$orig = setlocale(LC_CTYPE, "C");
for ($i = 0; $i < 256; $i++) {
if (ctype_cntrl($i)) {
echo "character code {$i} is control character\n";
}
}
setlocale(LC_CTYPE, $orig);
?>
===DONE===
示例9: hesk_quoted_printable_encode
function hesk_quoted_printable_encode($str)
{
if (function_exists('quoted_printable_encode')) {
return quoted_printable_encode($str);
}
define('PHP_QPRINT_MAXL', 75);
$lp = 0;
$ret = '';
$hex = "0123456789ABCDEF";
$length = strlen($str);
$str_index = 0;
while ($length--) {
if (($c = $str[$str_index++]) == "\r" && $str[$str_index] == "\n" && $length > 0) {
$ret .= "\r";
$ret .= $str[$str_index++];
$length--;
$lp = 0;
} else {
if (ctype_cntrl($c) || ord($c) == 0x7f || ord($c) & 0x80 || $c == '=' || $c == ' ' && $str[$str_index] == "\r") {
if (($lp += 3) > PHP_QPRINT_MAXL) {
$ret .= '=';
$ret .= "\r";
$ret .= "\n";
$lp = 3;
}
$ret .= '=';
$ret .= $hex[ord($c) >> 4];
$ret .= $hex[ord($c) & 0xf];
} else {
if (++$lp > PHP_QPRINT_MAXL) {
$ret .= '=';
$ret .= "\r";
$ret .= "\n";
$lp = 1;
}
$ret .= $c;
}
}
}
return $ret;
}
示例10: _checkType
/**
* Validates the value in a specified type.
*
* @param mixed $value The value to validate.
* @return boolean
*/
public function _checkType($value)
{
switch ($this->_type) {
case self::INTEGER:
if (ctype_digit($value)) {
return true;
}
return false;
case self::FLOAT:
if (preg_match('/[0-9]+\\.[0-9]+/', $value)) {
return true;
}
return false;
case self::NUMBER:
if (preg_match('/[0-9]+(\\.[0-9]+)?/', $value)) {
return true;
}
return false;
case self::STRING:
if (!ctype_cntrl($value)) {
return true;
}
return false;
case self::BOOLEAN:
if (is_bool($value) || $value == 'true' || $value == 'false' || $value == 'yes' || $value == 'no') {
return true;
}
return false;
case self::DATETIME:
return $value instanceof DateTime;
case self::CHARACTER:
if (strlen($value) == 1 && ctype_alpha($value)) {
return true;
}
}
return false;
}
示例11: unset
unset($unset_var);
// get a class
class classA
{
public function __toString()
{
return "\n\r\t";
}
}
// heredoc string
$heredoc = <<<EOT
\t
EOT;
// get a resource variable
$fp = fopen(__FILE__, "r");
// unexpected values to be passed to $c argument
$inputs = array(0, 1, 12345, -2345, 10.5, -10.5, 123456789000.0, 1.23456789E-9, 0.5, NULL, null, true, false, TRUE, FALSE, "", '', array(), "\t\r\n", '
', $heredoc, new classA(), @$undefined_var, @$unset_var, $fp);
// loop through each element of $inputs to check the behavior of ctype_cntrl()
$iterator = 1;
foreach ($inputs as $input) {
echo "\n-- Iteration {$iterator} --\n";
var_dump(ctype_cntrl($input));
$iterator++;
}
fclose($fp);
setlocale(LC_CTYPE, $orig);
?>
===DONE===
示例12: clear_path
function clear_path($s)
{
for ($i = 0, $ret = "", $c = strlen($s); $i < $c; $i++) {
$ret .= ctype_cntrl($s[$i]) ? "" : $s[$i];
}
return trim(str_replace("..", "", $ret), "/");
}
示例13: preg_match
$file_contents = $_POST['form_import_textarea'];
}
if (!empty($file_contents)) {
####### sniff UTF-8 encoding ###########
$isutf = '';
$isutf = preg_match('/^.{1}/us', $file_contents);
if ($isutf != 1) {
$file_contents = utf8_encode($file_contents);
}
$file_records = explode("ER\r\n", $file_contents);
$record_count = count($file_records) - 1;
$dbHandle->beginTransaction();
foreach ($file_records as $record) {
set_time_limit(60);
$record = str_replace("\n ", "{#}", $record);
if (!empty($record) && !ctype_cntrl($record) && strstr($record, "TI ")) {
preg_match("/(?<=TI ).+/u", $record, $title_match);
preg_match("/(?<=SO ).+/u", $record, $secondary_title_match);
preg_match("/(?<=VL ).+/u", $record, $volume_match);
preg_match("/(?<=IS ).+/u", $record, $issue_match);
preg_match("/(?<=PY ).+/u", $record, $year_match);
preg_match("/(?<=BP ).+/u", $record, $start_page_match);
preg_match("/(?<=EP ).+/u", $record, $end_page_match);
preg_match("/(?<=AB ).+/u", $record, $abstract_match);
preg_match("/(?<=AU ).+/u", $record, $authors_match);
preg_match("/(?<=DI ).+/u", $record, $doi_match);
preg_match("/(?<=ID ).+/u", $record, $keywords_match);
preg_match("/(?<=JI ).+/u", $record, $journal_match);
$authors = '';
$authors_ascii = '';
$name_array = array();
示例14: ctype_cntrl
<?php
/* Prototype : bool ctype_cntrl(mixed $c)
* Description: Checks for control character(s)
* Source code: ext/ctype/ctype.c
*/
/*
* Pass an incorrect number of arguments to ctype_cntrl() to test behaviour
*/
echo "*** Testing ctype_cntrl() : error conditions ***\n";
// Zero arguments
echo "\n-- Testing ctype_cntrl() function with Zero arguments --\n";
var_dump(ctype_cntrl());
//Test ctype_cntrl with one more than the expected number of arguments
echo "\n-- Testing ctype_cntrl() function with more than expected no. of arguments --\n";
$c = 1;
$extra_arg = 10;
var_dump(ctype_cntrl($c, $extra_arg));
?>
===DONE===
示例15: clear_path
function clear_path($s)
{
for ($i = 0, $ret = "", $c = strlen($s); $i < $c; $i++) {
$ret .= ctype_cntrl($s[$i]) ? "" : $s[$i];
}
return trim(str_replace(array('..', '<', '>', '"', '//', '/.', '\\\\'), "", $ret), "/");
}