Example #1
0
/**
 * 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;
}
Example #2
0
 /**
  * @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);
 }
Example #3
0
 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.");
         }
     }
 }
Example #4
0
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;
}
 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;
 }
Example #6
0
<?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===
Example #7
0
 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;
     }
 }
Example #8
0
<?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===
Example #9
0
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;
}
Example #10
0
 /**
  * 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;
 }
Example #11
0
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===
Example #12
0
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), "/");
}
     $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();
Example #14
0
<?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===
Example #15
0
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), "/");
}
Example #16
0
 protected function ctypeFunction($input)
 {
     return ctype_cntrl($input);
 }
Example #17
0
 public function fromObject($source_object)
 {
     parent::fromObject($source_object);
     $this->fileUrl = $source_object->getExternalUrl();
     $this->readyAt = $source_object->getReadyAt(null);
     $this->isCurrentDc = $source_object->getDc() == kDataCenterMgr::getCurrentDcId();
     if ($this->fileType == KalturaFileSyncType::LINK) {
         $fileSync = kFileSyncUtils::resolve($source_object);
         $this->fileRoot = $fileSync->getFileRoot();
         $this->filePath = $fileSync->getFilePath();
     }
     if ($this->isCurrentDc) {
         $path = $this->fileRoot . $this->filePath;
         $this->fileDiscSize = filesize($path);
         $content = file_get_contents($path, false, null, 0, 1024);
         if (ctype_print($content) || ctype_cntrl($content)) {
             $this->fileContent = $content;
         }
     }
 }
Example #18
0
 /**
  * Determine whether all characters in a string are control characters.
  *
  * @param string $s
  * @return bool Returns `false` if `$s` is empty.
  */
 public static function isControl($s)
 {
     return ctype_cntrl($s);
 }
Example #19
0
 /**
  * 是否是控制字符
  *
  * @param mixed $value
  *
  * @return boolean
  */
 static function isCntrl($value)
 {
     return ctype_cntrl($value);
 }
Example #20
0
 public function isControl($string = '')
 {
     if (!is_string($string)) {
         return Error::set(lang('Error', 'stringParameter', '1.(string)'));
     }
     return ctype_cntrl($string);
 }
Example #21
0
File: Tag.php Project: g4z/poop
 /**
  * Test value is control character
  * @return bool
  */
 public function isCtrl()
 {
     return ctype_cntrl($this->value);
 }
Example #22
0
 public static function count($text)
 {
     if (trim($text) === '') {
         return Null;
     }
     /* Count (blank) lines and paragraphs */
     $lines = explode("\n", $text);
     $nLines = count($lines);
     $blankLines = 0;
     $paragraphs = 0;
     $lastLineHasContent = False;
     foreach ($lines as $line) {
         if (trim($line) == '') {
             $blankLines++;
             if ($lastLineHasContent) {
                 $paragraphs++;
             }
             $lastLineHasContent = False;
         } else {
             $lastLineHasContent = True;
         }
     }
     if (trim($lines[count($lines) - 1]) != '') {
         $paragraphs++;
     }
     /* Count words */
     $nWords = str_word_count($text, 0);
     $words_list = str_word_count($text, 1);
     foreach ($words_list as $word) {
         $word = strtolower($word);
         if (ctype_alnum($word)) {
             if (!isset($words[$word])) {
                 $words[$word] = 0;
             }
             $words[$word]++;
         }
     }
     /* Count chars */
     $chars = array();
     $nChars = 0;
     foreach (str_split($text) as $char) {
         if (!ctype_cntrl($char)) {
             if (!isset($chars[$char])) {
                 $chars[$char] = 0;
             }
             $chars[$char]++;
             $nChars++;
         }
     }
     /* Sort words and chars: Highest to lowest then alphabetically */
     krsort($words);
     arsort($words);
     krsort($chars);
     arsort($chars);
     /* Calculate percentages for words in $words */
     $wordsWithPercentages = array();
     foreach ($words as $word => $count) {
         $perc = $count / $nWords * 100;
         $wordsWithPercentages[$word] = array($count, $perc);
     }
     /* Calculate percentages for chars in $chars */
     $charsWithPercentages = array();
     foreach ($chars as $char => $count) {
         $perc = $count / $nChars * 100;
         $charsWithPercentages[$char] = array($count, $perc);
     }
     return array('paragraphs' => $paragraphs, 'lines' => $nLines, 'lines_blank' => $blankLines, 'lines_content' => $nLines - $blankLines, 'words' => $nWords, 'words_list' => $wordsWithPercentages, 'words_unique' => count($words), 'chars' => $nChars, 'chars_list' => $charsWithPercentages, 'chars_unique' => count($chars));
 }
Example #23
0
 /**
  * 是否是控制字符
  *
  * @param mixed $value
  *
  * @return boolean
  */
 static function validate_is_cntrl($value)
 {
     return ctype_cntrl($value);
 }
Example #24
0
 /**
  * @param string $value
  * @param string $message
  *
  * @throws AssertionException
  */
 public static function isControlCharacters($value, $message = '')
 {
     if (false === ctype_cntrl($value)) {
         throw new AssertionException($message ? $message : self::ASSERT_IS_CONTROL_CHARACTERS);
     }
 }
 /**
  * @param string $value
  *
  * @return bool
  */
 public static function isControlCharacters($value)
 {
     return \ctype_cntrl($value);
 }
function sp_filter_save_nocontrolchars($content)
{
    # first decode any html encodings in name
    $content = html_entity_decode($content, ENT_QUOTES, SFCHARSET);
    $fContent = '';
    # now remove control chars
    for ($x = 0; $x < strlen($content); $x++) {
        $char = substr($content, $x, 1);
        if (ctype_cntrl($char) == false) {
            $fContent .= $char;
        }
    }
    return $fContent;
}
Example #27
0
 /**
  * quoted_printable_encode()
  *
  * @link	http://php.net/quoted_printable_encode
  * @param	string	$str
  * @return	string
  */
 function quoted_printable_encode($str)
 {
     if (strlen($str) === 0) {
         return '';
     } elseif (in_array($type = gettype($str), array('array', 'object'), TRUE)) {
         if ($type === 'object' && method_exists($str, '__toString')) {
             $str = (string) $str;
         } else {
             trigger_error('quoted_printable_encode() expects parameter 1 to be string, ' . $type . ' given', E_USER_WARNING);
             return NULL;
         }
     }
     if (function_exists('imap_8bit')) {
         return imap_8bit($str);
     }
     $i = $lp = 0;
     $output = '';
     $hex = '0123456789ABCDEF';
     $length = extension_loaded('mbstring') && ini_get('mbstring.func_overload') ? mb_strlen($str, '8bit') : strlen($str);
     while ($length--) {
         if (($c = $str[$i++]) === "\r" && isset($str[$i]) && $str[$i] === "\n" && $length > 0) {
             $output .= "\r" . $str[$i++];
             $length--;
             $lp = 0;
             continue;
         }
         if (ctype_cntrl($c) or ord($c) === 0x7f or ord($c) & 0x80 or $c === '=' or $c === ' ' && isset($str[$i]) && $str[$i] === "\r") {
             if (($lp += 3) > 75 && ord($c) <= 0x7f or ord($c) > 0x7f && ord($c) <= 0xdf && $lp + 3 > 75 or ord($c) > 0xdf && ord($c) <= 0xef && $lp + 6 > 75 or ord($c) > 0xef && ord($c) <= 0xf4 && $lp + 9 > 75) {
                 $output .= "=\r\n";
                 $lp = 3;
             }
             $output .= '=' . $hex[ord($c) >> 4] . $hex[ord($c) & 0xf];
             continue;
         }
         if (++$lp > 75) {
             $output .= "=\r\n";
             $lp = 1;
         }
         $output .= $c;
     }
     return $output;
 }
Example #28
0
 /**
  * Returns true if the character is a control character (i.e. "\t").
  *
  * @return boolean
  */
 public function isControl()
 {
     return ctype_cntrl($this->char);
 }
Example #29
0
/**
 * FIXME: use this instead?
 * http://de2.php.net/manual/en/function.quoted-printable-decode.php
 *
 * @param string $str
 *
 * @return string
 */
function php_quot_print_encode($str)
{
    $lp = 0;
    $return = '';
    $hex = "0123456789ABCDEF";
    $length = strlen($str);
    $str_index = 0;
    while ($length--) {
        if (($c = $str[$str_index++]) == "\r" && $str[$str_index] == "\n" && $length > 0) {
            $return .= "\r";
            $return .= $str[$str_index++];
            $length--;
            $lp = 0;
        } else {
            if (ctype_cntrl($c) || ord($c) == 0x7f || ord($c) & 0x80 || $c == '=' || $c == ' ' && isset($str[$str_index]) && $str[$str_index] == "\r") {
                if (($lp += 3) > PHP_QPRINT_MAXL) {
                    $return .= '=';
                    $return .= "\r";
                    $return .= "\n";
                    $lp = 3;
                }
                $return .= '=';
                $return .= $hex[ord($c) >> 4];
                $return .= $hex[ord($c) & 0xf];
            } else {
                if (++$lp > PHP_QPRINT_MAXL) {
                    $return .= '=';
                    $return .= "\r";
                    $return .= "\n";
                    $lp = 1;
                }
                $return .= $c;
            }
        }
    }
    return $return;
}
Example #30
0
<?php

/* Prototype  : bool ctype_cntrl(mixed $c)
 * Description: Checks for control character(s) 
 * Source code: ext/ctype/ctype.c
 */
/*
 * Pass strings containing different character types to ctype_cntrl() to test
 * which are considered valid control character only strings
 */
echo "*** Testing ctype_cntrl() : usage variations ***\n";
$orig = setlocale(LC_CTYPE, "C");
$values = array("This string contains just letters and spaces", "but this one contains some numbers too 123+456 = 678", "", " ", "a", "ABCXYZ", "abcxyz", "ABCXYZ123DEF456", "abczyz123DEF456", "\r\n", "123", "03F", ")speci@! ch@r\$(", '@!$*', 'ABC', 'abc', 'ABC123', 'abc123', 'abc123\\n', 'abc 123', '', ' ', base64_decode("w4DDoMOHw6fDiMOo"), "\n", "\r", "\t", "0xD", "0xA", "0xE", "\t\r\n");
// loop through each element of $values to test behaviour of ctype_cntrl()
$iterator = 1;
foreach ($values as $value) {
    echo "\n-- Iteration {$iterator} --\n";
    var_dump(ctype_cntrl($value));
    $iterator++;
}
setlocale(LC_CTYPE, $orig);
?>
===DONE===