Example #1
1
 public function encode(string $input)
 {
     $output = "";
     $prevc = NULL;
     for ($i = 0; $i < \strlen($input); $i++) {
         $c = $input[$i];
         if ("" < $c) {
             if ($this->errorOnNonASCII) {
                 throw new \Exception("Error at position {$i}: non-ASCII byte '{$c}'");
             }
         } else {
             $c = strtolower($c);
         }
         $replacement = $this->letters[$c] ?? $this->digits[$c] ?? NULL;
         if ($replacement !== NULL && !($c === "." && $replacement === ($this->digits[$c] ?? NULL) && !ctype_digit($prevc))) {
             // Insert spaces at word boundaries
             if ($prevc !== NULL && !ctype_space($prevc) && !ctype_punct($prevc) || $prevc === '.' && ctype_digit($c)) {
                 $output .= ' ';
             }
             $output .= $replacement;
         } else {
             $output .= $c;
         }
         $prevc = $c;
     }
     return $output;
 }
Example #2
0
 public function getSummary($text)
 {
     $sentences = $this->config->trigger('get_sentences', $text);
     $candidates = [];
     $x = microtime(true);
     foreach ($sentences as $id => $t) {
         try {
             $words = $this->config->trigger('get_words', $t);
             $words = $this->config->trigger('filter_keywords', $words);
             $words = $this->config->trigger('normalize_keywords', $words);
             $words = array_filter($words, function ($word) {
                 return !ctype_punct($word);
             });
             $candidates[$id] = $words;
         } catch (\Exception $e) {
         }
     }
     $pr = new SummaryPageRank();
     $sorted = $pr->sort($candidates);
     $keys = array_slice($sorted, 0, ceil(count($sorted) * 0.05), true);
     $txt = "";
     foreach (array_keys($keys) as $key) {
         $txt .= $sentences[$key] . "\n";
     }
     return $txt;
 }
Example #3
0
File: rave.php Project: ryanve/rave
 /**
  * Rave::is_dust             Test for strings that consist only of punctuation and/or whitespace characters.
  *                           
  * @param   mixed            $ukn   is the unknown variable to test.
  * @return  boolean          true  for strings that contain only whitespace or punctuation characters.
  *                           false for non-strings and strings containing letters or numbers.
  *                           
  */
 public static function is_dust($ukn)
 {
     // In the third test, replace whitespaces with # to make them punctuation so they'll count
     // as dust. The array was derived from the list @link php.net/manual/en/function.trim.php
     $whitespace = array(' ', "\\s", "\t", "\n", "\r", "", "\v");
     return isset($ukn) && is_string($ukn) && ctype_punct(str_replace($whitespace, '#', $ukn));
 }
Example #4
0
/**
 * Returns whether or not the $value of a given password option $key is valid.
 */
function isOptionValid($key, $value)
{
    $is_option_valid = TRUE;
    // check if letter_case function does not exist
    if ($key == "letter_case" && !function_exists($value)) {
        $is_option_valid = FALSE;
    }
    // check if min_password_length is not within range
    if ($key == "min_password_length" && (!ctype_digit($value) || $value < 8 || $value > 32)) {
        $is_option_valid = FALSE;
    }
    // check if min_words is not within range
    if ($key == "min_words" && (!ctype_digit($value) || $value < 2 || $value > 9)) {
        $is_option_valid = FALSE;
    }
    // check if num_digits is not within range
    if ($key == "num_digits" && (!ctype_digit($value) || $value < 0 || $value > 3)) {
        $is_option_valid = FALSE;
    }
    // check if num_symbols is not within range
    if ($key == "num_symbols" && (!ctype_digit($value) || $value < 0 || $value > 3)) {
        $is_option_valid = FALSE;
    }
    // check if separator is not an empty string, whitespace or punctuation
    if ($key == "separator" && !($value === "" || ctype_space($value) || ctype_punct($value))) {
        $is_option_valid = FALSE;
    }
    return $is_option_valid;
}
	function getOptionAbbreviations() {
		if ( is_null( $this->abbrevs ) ) {
			$abbrevs = array();
			foreach ( $this->question->getOptions() as $option ) {
				$text = $option->getMessage( 'text' );
				$parts = explode( ' ', $text );
				$initials = '';
				foreach ( $parts as $part ) {
					if ( $part === '' || ctype_punct( $part[0] ) ) {
						continue;
					}
					$initials .= $part[0];
				}
				if ( isset( $abbrevs[$initials] ) ) {
					$index = 2;
					while ( isset( $abbrevs[$initials . $index] ) ) {
						$index++;
					}
					$initials .= $index;
				}
				$abbrevs[$initials] = $option->getId();
			}
			$this->abbrevs = array_flip( $abbrevs );
		}
		return $this->abbrevs;
	}
Example #6
0
 public function isValid($value)
 {
     $this->_setValue($value);
     $valueString = (string) $value;
     if (ctype_punct($value)) {
         $this->_error(self::MSG_FILENAME_INVALID);
         return false;
     }
     return true;
 }
Example #7
0
 /**
  * rawFilter takes a string and process it
  *
  * @param $tag string
  * @return filtered raw tag
  */
 public function rawFilter($tagstring)
 {
     $tagstring = mb_ereg_replace(' +', ' ', trim($tagstring));
     $tagstring = mb_ereg_replace("[\r\t\n]", "", $tagstring);
     // http://www.asciitable.com/
     $tagstring = trim($tagstring, "\"'&,");
     if (ctype_punct($tagstring)) {
         $tagstring = '';
     }
     return $tagstring;
 }
function sc_get_mention_list($content)
{
    $initiator = '@';
    $max_number_of_words = sc_username_max_words();
    $mention_list = array();
    $content_length = strlen($content);
    $loc = stripos($content, $initiator);
    while ($loc !== false) {
        $current_user = null;
        if ($loc == 0 || $content[$loc - 1] == ' ' || ctype_punct($content[$loc - 1])) {
            $word_count = 1;
            $last_word = '';
            $s_index = $loc;
            while ($word_count <= $max_number_of_words) {
                if ($content[$s_index] == $initiator) {
                    $s_index++;
                    for (; $s_index < $content_length && $content[$s_index] != ' '; $s_index++) {
                        $last_word .= $content[$s_index];
                    }
                } else {
                    if ($content[$s_index] == ' ') {
                        $s_index++;
                        $last_word .= ' ';
                        for (; $s_index < $content_length && $content[$s_index] != ' '; $s_index++) {
                            $last_word .= $content[$s_index];
                        }
                    } else {
                        break;
                    }
                }
                if (sc_user_exists($last_word)) {
                    $current_user = $last_word;
                }
            }
            $word_count++;
        }
        if ($current_user !== null) {
            $mention_list[] = $current_user;
        }
        $loc = stripos($content, $initiator, $loc + 1);
    }
    return $mention_list;
}
Example #9
0
 function isValidPassword($password)
 {
     if (strlen($password) < getMinPasswordLength()) {
         return false;
     }
     $haveAlpha = $haveDigit = false;
     for ($i = 0; $i < strlen($password); $i++) {
         $c = $password[$i];
         if (ctype_alpha($c)) {
             $haveAlpha = true;
         } else {
             if (ctype_digit($c)) {
                 $haveDigit = true;
             } else {
                 if (!ctype_punct($c)) {
                     return false;
                 }
             }
         }
     }
     return $haveAlpha && $haveDigit ? true : false;
 }
Example #10
0
function inputCheck($data, $fieldName)
{
    global $errors;
    if (empty($data)) {
        fieldRequired($fieldName);
        ++$errors;
        $retval = "";
    }
    if (ctype_alpha($data)) {
        numRequired($fieldName);
        ++$errors;
        $retval = "";
    }
    if (ctype_punct($data)) {
        numRequired($fieldName);
        ++$errors;
        $retval = "";
    } else {
        $retval = $data;
    }
    return $retval;
}
Example #11
0
function capture_translation($id, $domain, $string)
{
    global $captureDomain, $newTranslations, $currentTranslations;
    if ($domain != $captureDomain) {
        return;
    }
    if (empty($id)) {
        return;
    }
    if (is_numeric($id) || ctype_punct($id)) {
        return;
        // Not supposed to be a translatable string
    }
    if (isset($currentTranslations[$id]) && $currentTranslations[$id] === false) {
        if (isset($_GET['include_disabled'])) {
            $newTranslations[$id] = false;
        }
        return;
        // Disabled translation
    }
    $newTranslations[$id] = html_entity_decode($string);
}
 private function ToCamelCase($name)
 {
     $result = '';
     $reader = new System\StringReader($name);
     $nextUp = true;
     while (false !== ($ch = $reader->ReadChar())) {
         if (ctype_punct($ch) || ctype_space($ch)) {
             $nextUp = true;
             continue;
         }
         if (System\String::IsLetter($ch)) {
             if ($nextUp) {
                 $result .= System\String::ToUpper($ch);
                 $nextUp = false;
             } else {
                 $result .= $ch;
             }
         }
         //else skip.
     }
     return $result;
 }
Example #13
0
     $char = substr($info['new'], $i, 1);
     if (ctype_lower($char)) {
         $lower++;
         $alpha++;
         $alnum++;
         $classes['lower'] = 1;
     } elseif (ctype_upper($char)) {
         $upper++;
         $alpha++;
         $alnum++;
         $classes['upper'] = 1;
     } elseif (ctype_digit($char)) {
         $num++;
         $alnum++;
         $classes['number'] = 1;
     } elseif (ctype_punct($char)) {
         $symbol++;
         $classes['symbol'] = 1;
     } elseif (ctype_space($char)) {
         $space++;
         $classes['symbol'] = 1;
     }
 }
 // Check reamaining password policy options.
 if (isset($password_policy['minUpper']) && $password_policy['minUpper'] > $upper) {
     $notification->push(sprintf(_("Your new password must contain at least %d uppercase characters."), $password_policy['minUpper']), 'horde.warning');
     break;
 }
 if (isset($password_policy['minLower']) && $password_policy['minLower'] > $lower) {
     $notification->push(sprintf(_("Your new password must contain at least %d lowercase characters."), $password_policy['minLower']), 'horde.warning');
     break;
Example #14
0
File: Tag.php Project: g4z/poop
 /**
  * Test value is punctuation
  * @return bool
  */
 public function isPunct()
 {
     return ctype_punct($this->value);
 }
Example #15
0
 public function next_token()
 {
     if ($this->error_message) {
         return $this->tok;
     }
     $q = $this->query;
     $start = 0;
     while (($ch = substr($q, $start, 1)) !== FALSE && ctype_space($ch)) {
         $start++;
     }
     if ($ch === FALSE) {
         $this->tok = array(TYPE => "eof");
         return FALSE;
     }
     $ret = FALSE;
     $end = $start;
     if ($ch == '`') {
         while (($ch = substr($q, ++$end, 1)) !== FALSE && $ch != '`') {
         }
         $ret = array(TYPE => ID, VALUE => substr($q, $start + 1, $end - $start - 1));
         ++$end;
     } else {
         if (ctype_digit($ch) || $ch == '.') {
             $ndot = $ch == '.' ? 1 : 0;
             while (($ch = substr($q, ++$end, 1)) !== FALSE) {
                 if (!ctype_digit($ch)) {
                     if ($ndot || $ch != '.') {
                         break;
                     }
                     $ndot = 1;
                 }
             }
             if ($ch == 'e' || $ch == 'E') {
                 $ch = substr($q, ++$end, 1);
                 if ($ch == '+' || $ch == '-') {
                     $ch = substr($q, ++$end, 1);
                 }
                 while (ctype_digit($ch)) {
                     $ch = substr($q, ++$end, 1);
                 }
             }
             $ret = array(TYPE => NUMBER, VALUE => substr($q, $start, $end - $start));
         } else {
             if (ctype_punct($ch)) {
                 $end = $start + 1;
                 $pos = strpos(",()=*+-/", $ch);
                 if (!($pos === FALSE)) {
                     $ret = array(TYPE => OPERATOR, VALUE => $ch);
                     $end = $start + 1;
                 } else {
                     $two = substr($q, $start, 2);
                     if ($two == "!=" || $two == "<>" || $two == "<=" || $two == ">=") {
                         $ret = array(TYPE => OPERATOR, VALUE => $two);
                         $end++;
                     } else {
                         if ($ch == '<' || $ch == '>') {
                             $ret = array(TYPE => OPERATOR, VALUE => $ch);
                         } else {
                             if ($ch == "'" || $ch == '"') {
                                 $quote = $ch;
                                 $ret = "";
                                 while (($ch = substr($q, $end++, 1)) !== FALSE) {
                                     if ($ch == $quote) {
                                         break;
                                     }
                                     if ($ch == "\\") {
                                         $ch = substr($q, $end++, 1);
                                     }
                                     $ret .= $ch;
                                 }
                                 $ret = array(TYPE => STRING, VALUE => $ret);
                             } else {
                                 $ret = array(TYPE => UNKNOWN);
                             }
                         }
                     }
                 }
             } else {
                 if (ctype_alpha($ch) || $ch == '_') {
                     while (($ch = substr($q, ++$end, 1)) !== FALSE && (ctype_alnum($ch) || $ch == '_')) {
                     }
                     $ret = substr($q, $start, $end - $start);
                     if (isset($this->reserved[$ret])) {
                         $ret = array(TYPE => RESID, VALUE => $ret);
                     } else {
                         $ret = array(TYPE => ID, VALUE => $ret);
                     }
                 } else {
                     $ret = array(TYPE => UNKNOWN);
                 }
             }
         }
     }
     $this->query = substr($q, $end);
     $this->tok = $ret;
     return $ret;
 }
Example #16
0
 public function isNonAlnum($string = '')
 {
     if (!is_string($string)) {
         return Error::set(lang('Error', 'stringParameter', '1.(string)'));
     }
     return ctype_punct($string);
 }
Example #17
0
 protected function ctypeFunction($input)
 {
     return ctype_punct($input);
 }
 /**
  * @param string $value
  *
  * @return bool
  */
 public static function isPunctuation($value)
 {
     return \ctype_punct($value);
 }
Example #19
0
 /**
  * 是否是标点符号
  *
  * @param mixed $value
  *
  * @return boolean
  */
 static function validate_is_punct($value)
 {
     return ctype_punct($value);
 }
 protected function getGraph(array $ngrams)
 {
     $outlinks = array();
     $graph = array();
     $values = array();
     $total = count($ngrams);
     for ($i = 0; $i < $total; $i++) {
         if (ctype_punct($ngrams[$i])) {
             continue;
         }
         for ($e = $i; $e < $total && $e <= $i + 5; $e++) {
             if ($i > $total || $e > $total) {
                 continue;
             }
             if ($ngrams[$e] == $ngrams[$i]) {
                 continue;
             }
             if (ctype_punct($ngrams[$e])) {
                 break;
             }
             foreach (array($i, $e) as $id) {
                 if (empty($outlinks[$ngrams[$id]])) {
                     $outlinks[$ngrams[$id]] = 0;
                 }
                 if (empty($graph[$ngrams[$id]])) {
                     $graph[$ngrams[$id]] = array();
                 }
                 $outlinks[$ngrams[$id]]++;
                 /* increment outlink counter */
                 $values[$ngrams[$id]] = 0.15;
                 /* initial value */
             }
             $graph[$ngrams[$e]][] = $ngrams[$i];
             $graph[$ngrams[$i]][] = $ngrams[$e];
         }
     }
     return compact('graph', 'values', 'outlinks');
 }
Example #21
0
File: Auth.php Project: horde/horde
 /**
  * Checks whether a password matches some expected policy.
  *
  * @param string $password  A password.
  * @param array $policy     A configuration with policy rules. Supported
  *                          rules:
  *
  *   - minLength:   Minimum length of the password
  *   - maxLength:   Maximum length of the password
  *   - maxSpace:    Maximum number of white space characters
  *
  *     The following are the types of characters required in a
  *     password.  Either specific characters, character classes,
  *     or both can be required.  Specific types are:
  *
  *   - minUpper:    Minimum number of uppercase characters
  *   - minLower:    Minimum number of lowercase characters
  *   - minNumeric:  Minimum number of numeric characters (0-9)
  *   - minAlphaNum: Minimum number of alphanumeric characters
  *   - minAlpha:    Minimum number of alphabetic characters
  *   - minSymbol:   Minimum number of punctuation / symbol characters
  *   - minNonAlpha: Minimum number of non-alphabetic characters
  *
  *     Alternatively (or in addition to), the minimum number of
  *     character classes can be configured by setting the
  *     following.  The valid range is 0 through 4 character
  *     classes may be required for a password. The classes are:
  *     'upper', 'lower', 'number', and 'symbol'.  For example: A
  *     password of 'p@ssw0rd' satisfies three classes ('number',
  *     'lower', and 'symbol'), while 'passw0rd' only satisfies two
  *     classes ('lower' and 'number').
  *
  *   - minClasses:  Minimum number (0 through 4) of character
  *                  classes.
  *
  * @throws Horde_Auth_Exception if the password does not match the policy.
  */
 public static function checkPasswordPolicy($password, array $policy)
 {
     // Check max/min lengths if specified in the policy.
     if (isset($policy['minLength']) && strlen($password) < $policy['minLength']) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::t("The password must be at least %d characters long!"), $policy['minLength']));
     }
     if (isset($policy['maxLength']) && strlen($password) > $policy['maxLength']) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::t("The password is too long; passwords may not be more than %d characters long!"), $policy['maxLength']));
     }
     // Dissect the password in a localized way.
     $classes = array();
     $alpha = $nonalpha = $alnum = $num = $upper = $lower = $space = $symbol = 0;
     for ($i = 0; $i < strlen($password); $i++) {
         $char = substr($password, $i, 1);
         if (ctype_lower($char)) {
             $lower++;
             $alpha++;
             $alnum++;
             $classes['lower'] = 1;
         } elseif (ctype_upper($char)) {
             $upper++;
             $alpha++;
             $alnum++;
             $classes['upper'] = 1;
         } elseif (ctype_digit($char)) {
             $num++;
             $nonalpha++;
             $alnum++;
             $classes['number'] = 1;
         } elseif (ctype_punct($char)) {
             $symbol++;
             $nonalpha++;
             $classes['symbol'] = 1;
         } elseif (ctype_space($char)) {
             $space++;
             $classes['symbol'] = 1;
         }
     }
     // Check reamaining password policy options.
     if (isset($policy['minUpper']) && $policy['minUpper'] > $upper) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::ngettext("The password must contain at least %d uppercase character.", "The password must contain at least %d uppercase characters.", $policy['minUpper']), $policy['minUpper']));
     }
     if (isset($policy['minLower']) && $policy['minLower'] > $lower) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::ngettext("The password must contain at least %d lowercase character.", "The password must contain at least %d lowercase characters.", $policy['minLower']), $policy['minLower']));
     }
     if (isset($policy['minNumeric']) && $policy['minNumeric'] > $num) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::ngettext("The password must contain at least %d numeric character.", "The password must contain at least %d numeric characters.", $policy['minNumeric']), $policy['minNumeric']));
     }
     if (isset($policy['minAlpha']) && $policy['minAlpha'] > $alpha) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::ngettext("The password must contain at least %d alphabetic character.", "The password must contain at least %d alphabetic characters.", $policy['minAlpha']), $policy['minAlpha']));
     }
     if (isset($policy['minAlphaNum']) && $policy['minAlphaNum'] > $alnum) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::ngettext("The password must contain at least %d alphanumeric character.", "The password must contain at least %d alphanumeric characters.", $policy['minAlphaNum']), $policy['minAlphaNum']));
     }
     if (isset($policy['minNonAlpha']) && $policy['minNonAlpha'] > $nonalpha) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::ngettext("The password must contain at least %d numeric or special character.", "The password must contain at least %d numeric or special characters.", $policy['minNonAlpha']), $policy['minNonAlpha']));
     }
     if (isset($policy['minClasses']) && $policy['minClasses'] > array_sum($classes)) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::t("The password must contain at least %d different types of characters. The types are: lower, upper, numeric, and symbols."), $policy['minClasses']));
     }
     if (isset($policy['maxSpace']) && $policy['maxSpace'] < $space) {
         if ($policy['maxSpace'] > 0) {
             throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::t("The password must contain less than %d whitespace characters."), $policy['maxSpace'] + 1));
         }
         throw new Horde_Auth_Exception(Horde_Auth_Translation::t("The password must not contain whitespace characters."));
     }
     if (isset($policy['minSymbol']) && $policy['minSymbol'] > $symbol) {
         throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::ngettext("The password must contain at least %d symbol character.", "The password must contain at least %d symbol characters.", $policy['minSymbol']), $policy['minSymbol']));
     }
 }
Example #22
0
 /**
  * @param string $value
  * @param string $message
  *
  * @throws AssertionException
  */
 public static function isPunctuation($value, $message = '')
 {
     if (false === ctype_punct($value)) {
         throw new AssertionException($message ? $message : self::ASSERT_IS_PUNCTUATION);
     }
 }
Example #23
0
 /**
  * Determine whether all characters in a string are punctuation.
  *
  * @param string $s
  * @return bool Returns `false` if `$s` is empty.
  */
 public static function isPunctuation($s)
 {
     return ctype_punct($s);
 }
Example #24
0
/* Prototype  : bool ctype_punct(mixed $c)
 * Description: Checks for any printable character which is not whitespace 
 * or an alphanumeric character 
 * Source code: ext/ctype/ctype.c
 */
/*
 * Pass different octal and hexadecimal values to ctype_punct() to test behaviour
 */
echo "*** Testing ctype_punct() : usage variations ***\n";
$orig = setlocale(LC_CTYPE, "C");
$octal_values = array(041, 042, 043, 044);
$hex_values = array(0x21, 0x22, 0x23, 0x24);
echo "\n-- Octal Values --\n";
$iterator = 1;
foreach ($octal_values as $c) {
    echo "-- Iteration {$iterator} --\n";
    var_dump(ctype_punct($c));
    $iterator++;
}
echo "\n-- Hexadecimal Values --\n";
$iterator = 1;
foreach ($hex_values as $c) {
    echo "-- Iteration {$iterator} --\n";
    var_dump(ctype_punct($c));
    $iterator++;
}
setlocale(LC_CTYPE, $orig);
?>
===DONE===
Example #25
0
 /**
  * Validate username format.
  *
  * @param string $value Value of data to be validated
  * @param int $minLength Minimum length
  * @param int $maxLength Maximum length
  * @param string $msg Custom error message
  * @return string
  */
 public function testUsername($value, $minLength = 4, $maxLength = 12, $msg = null)
 {
     if (!preg_match('/^[a-zA-Z][a-zA-Z.0-9_-]{' . ($minLength - 1) . ',' . $maxLength . '}$/i', $value)) {
         if ($msg !== null) {
             return $msg;
         }
         return "User name must be {$minLength}-{$maxLength} characters. Only characters, dots, digits, underscore & hyphen are allowed.";
     } else {
         if (strpos($value, '..') !== False) {
             if ($msg !== null) {
                 return $msg;
             }
             return "User name cannot consist of 2 continuous dots.";
         } else {
             if (strpos($value, '__') !== False) {
                 if ($msg !== null) {
                     return $msg;
                 }
                 return "User name cannot consist of 2 continuous underscore.";
             } else {
                 if (strpos($value, '--') !== False) {
                     if ($msg !== null) {
                         return $msg;
                     }
                     return "User name cannot consist of 2 continuous dash.";
                 } else {
                     if (strpos($value, '.-') !== False || strpos($value, '-.') !== False || strpos($value, '._') !== False || strpos($value, '_.') !== False || strpos($value, '_-') !== False || strpos($value, '-_') !== False) {
                         if ($msg !== null) {
                             return $msg;
                         }
                         return "User name cannot consist of 2 continuous punctuation.";
                     } else {
                         if (ctype_punct($value[0])) {
                             if ($msg !== null) {
                                 return $msg;
                             }
                             return "User name cannot start with a punctuation.";
                         } else {
                             if (ctype_punct(substr($value, strlen($value) - 1))) {
                                 if ($msg !== null) {
                                     return $msg;
                                 }
                                 return "User name cannot end with a punctuation.";
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #26
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;
     }
 }
 public function _testFinalPunctuation($en, $fr)
 {
     $ignoredPunctuation = ['#', '°', ')', '"', '>'];
     // Supprime les espaces de fin
     $en = \rtrim($en);
     $fr = \rtrim($fr);
     $lastLetterEn = \substr($en, -1);
     $lastLetterFr = \substr($fr, -1);
     if (!\in_array($lastLetterEn, $ignoredPunctuation) && \ctype_punct($lastLetterEn)) {
         if (!\in_array($lastLetterFr, $ignoredPunctuation)) {
             $this->assertTrue(\ctype_punct($lastLetterFr), "Il semble qu'il manque la ponctuation de la fin de chaîne.");
         }
     }
 }
Example #28
0
//get an unset variable
$unset_var = 10;
unset($unset_var);
// get a class
class classA
{
    public function __toString()
    {
        return ",<.>";
    }
}
// heredoc string
$heredoc = <<<EOT
[{}]
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(), ";:'@", '#~/?', $heredoc, new classA(), @$undefined_var, @$unset_var, $fp);
// loop through each element of $inputs to check the behavior of ctype_punct
$iterator = 1;
foreach ($inputs as $input) {
    echo "\n-- Iteration {$iterator} --\n";
    var_dump(ctype_punct($input));
    $iterator++;
}
fclose($fp);
setlocale(LC_CTYPE, $orig);
?>
===DONE===
Example #29
0
 function ctype_print($text)
 {
     return ctype_punct($text) && ctype_graph($text);
 }
Example #30
0
 /**
  * Returns true if the character is a mark.
  *
  * @return boolean
  */
 public function isMark()
 {
     return ctype_punct($this->char);
 }