function __call($func, $args) { $di = property_exists($this, 'di') && $this->di instanceof Di ? $this->di : Di::getInstance(); if (substr($func, 0, 4) == 'call' && ctype_upper(substr($func, 4, 1)) && (method_exists($this, $m = lcfirst(substr($func, 4))) || method_exists($this, $m = '_' . $m))) { $params = $di->methodGetParams($this, $m, $args); $closure = function () use($m, $params) { return call_user_func_array([$this, $m], $params); }; $closure->bindTo($this); return $closure(); } $method = '_' . $func; if (method_exists($this, $method)) { if (!(new \ReflectionMethod($this, $method))->isPublic()) { throw new \RuntimeException("The called method is not public."); } return $di->method($this, $method, $args); } if (($c = get_parent_class($this)) && method_exists($c, __FUNCTION__)) { $m = new \ReflectionMethod($c, __FUNCTION__); $dc1 = $m->getDeclaringClass()->name; $dc2 = (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->name; $dc3 = get_class($this); if ($dc1 != $dc2 || $dc2 != $dc3 && $dc1 != $dc3) { return parent::__call($func, $args); } } throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '->' . $func); }
public function __call($method, $arguments) { if (empty($arguments)) { $this->query .= "/{$method}"; return $this; } if (!is_array($arguments)) { throw new \Exception("Method {$method}() must have an array argument."); } if (ctype_upper($method[0]) && preg_match_all('/([A-Z]{1}[a-z]+)/', $method)) { throw new \Exception('Method names must be declared in camelCase.'); } elseif (!ctype_upper($method[0]) && preg_match_all('/([A-Z]{1}[a-z]+)/', $method)) { $pieces = preg_split('/(?=[A-Z])/', $method); foreach ($pieces as $word) { if (!ctype_upper($word[0])) { $this->query .= "/{$word}"; } else { $this->query .= "_{$word}"; } } } elseif (!ctype_upper($method[0]) && !preg_match_all('/([A-Z]{1}[a-z]+)/', $method)) { $this->query .= "/{$method}"; } else { throw new \Exception('Something went wrong. Bad method name i guess.'); } return $this->request(strtolower($this->query), $arguments[0]); }
function queryErrorHandlingISO() { if (empty($_GET['iso']) || is_numeric($_GET['iso']) || strlen($_GET['iso']) != 2 || !ctype_upper($_GET['iso'])) { header("Location: error.php"); die; } }
function _genderise($old_pre, $old, $old_post, $new) { // Determine case $case = NULL; // work it out here... if (ctype_upper($old)) { $case = 'upper'; } if (ctype_lower($old)) { $case = 'lower'; } if (preg_match('/[A-Z][a-z]+/', $old)) { $case = 'title'; } // Transform string switch ($case) { case 'lower': return $old_pre . strtolower($new) . $old_post; break; case 'upper': return $old_pre . strtoupper($new) . $old_post; break; case 'title': return $old_pre . title_case($new) . $old_post; break; } return $old_pre . $new . $old_post; }
function parse_class_path($class_name) { // Парсим директории $directories = array_reverse(explode('_', $class_name)); foreach ($directories as &$directory) { $new_directory = ''; for ($i = 0; $i < strlen($directory); $i++) { // Если это большая буква, то добавляем перед ней '_' if ($i != 0 && ctype_upper($directory[$i])) $new_directory .= '_'; $new_directory .= $directory[$i]; } $directory = strtolower($new_directory); } $class_path = implode('/', $directories); return $class_path; }
function executeDir($directory) { $iterator = new DirectoryIterator($directory); while ($iterator->valid()) { $entry = $iterator->getFilename(); $path = $directory . '/' . $entry; $iterator->next(); if ($entry[0] == '.') { continue; } if (is_file($path)) { if (substr($entry, -4) != '.php') { continue; } if (ctype_upper($entry[0])) { $test = new DocTest($path); if ($test->failed()) { echo $test->toString(); $this->fail('Doc test failed.'); } else { if ($test->numOfPassed()) { echo ','; } else { echo ' '; } } } } elseif (is_dir($path)) { $this->executeDir($path); } } }
function crypto($n, $string, $k) { $low = range('a', 'z'); $high = range('A', 'Z'); $newLetters = []; for ($i = 0; $i < $n; $i++) { $letter = $string[$i]; switch (true) { case ctype_upper($letter): $off = offsetK(array_search($letter, $high) + $k); $new = array_slice($high, $off, 1)[0]; break; case ctype_lower($letter): $off = offsetK(array_search($letter, $low) + $k); $new = array_slice($low, $off, 1)[0]; break; case ctype_digit($letter): $new = $letter; break; default: $new = $letter; break; } $newLetters[] = $new; } return implode('', $newLetters); }
/** * Converts a CamelCase string to underscores * Used to convert pathnames * e.g. CamelCase/Path -> camel_case_path * * @param string $string * @throws \Exception when empty string passed is not a string * @throws \Exception when empty string is passed * * @return string $string */ public static function convertCamelCaseToUnderscore($string) { $new_parts = array(); if (!is_string($string)) { throw new \Exception('Unexpected value for string in Utilities::convertCamelCaseToUnderscore expecting `string`'); } if (strlen($string) < 1) { throw new \Exception('Cannot convert empty string from camelCase to underscore'); } if (substr($string, 0, 1) === '/') { $string = preg_replace('/^(\\/+)/', '', $string); } if (substr($string, strlen($string) - 1) === '/') { $string = preg_replace('/(\\/+)$/', '', $string); } $parts = explode('/', $string); foreach ($parts as $index => $part) { $replacement = strtolower(preg_replace('/([A-Z])/', '_$1', $part)); if (ctype_upper(substr($part, 0, 1)) === true) { $part = substr($replacement, 1); } else { $part = $replacement; } $new_parts[] = $part; } $string = implode('_', $new_parts); return $string; }
public function loadClass($oopElement) { $ds = DIRECTORY_SEPARATOR; $oopElementOriginal = $oopElement; $oopElement = str_replace(array('\\', '/'), array($ds, $ds), $oopElement); $tmp = explode($ds, $oopElement); $oopElementName = end($tmp); $suffix = ".class"; if (strpos($oopElementName, 'I') === 0 && ctype_upper(substr($oopElementName, 0, 2))) { $suffix = ".interface"; } $suffix .= ".php"; if (isset($tmp[0])) { $tmp[0] = lcfirst($tmp[0]); } if (isset($tmp[1])) { $tmp[1] = lcfirst($tmp[1]); } $oopElement = implode($ds, $tmp); $file = $this->rootDir . str_replace('\\', $ds, $oopElement) . $suffix; if (is_file($file) && !class_exists($oopElementOriginal)) { /** @noinspection PhpIncludeInspection */ require $file; } }
/** * {@inheritdoc} */ protected function run(CommitInterface $commit) { $firstLetter = substr($commit->getMessage(), 0, 1); if (!ctype_upper($firstLetter)) { $this->addViolation($commit); } }
function outputCountriesWithVisits($dbAdapter) { $id = $_GET[continent]; if (!empty($id) && !is_numeric($id) && strlen($id) == 2 && ctype_upper($id)) { $gateCountry = new CountryTableGateway($dbAdapter); $result = $gateCountry->findCountriesWithCountsById($id); echo '<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp"> <thead> <tr> <th class="mdl-data-table__cell--non-numeric">Country</th> <th>Visits</th> </tr> </thead> <tbody>'; foreach ($result as $row) { echo '<tr> <td class="mdl-data-table__cell--non-numeric">' . $row->CountryName . '</td> <td>' . $row->VisitsFromCountry . '</td> </tr>'; } echo '</tbody> </table>'; } else { echo "<h2>Chosen continent does not exist</h2>"; } }
function mapi_break_into_sentences($input) { $text = trim(strip_tags($input)); $text_array = explode('.', $text); $sentences = array(); $sentence = ''; if (sizeof($text_array) < 1) { return $text; } for ($i = 0; $i < sizeof($text_array); $i++) { $fos_uppercase = false; if (isset($text_array[$i + 1])) { if (ctype_upper(substr($text_array[$i + 1], 0, 1))) { $fos_uppercase = true; } if (ctype_upper(substr($text_array[$i + 1], 1, 1))) { $fos_uppercase = true; } } else { $fos_uppercase = true; } $sentence .= $text_array[$i] . '.'; if ($fos_uppercase) { $sentences[] = $sentence; $sentence = ''; } } return $sentences; }
function bold() { $this->CI =& get_instance(); $content = ""; $output = $this->CI->output->get_output(); $dom = new DOMDocument(); $dom->loadHTML($output); $finder = new DomXPath($dom); $classname = "lead"; $nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' {$classname} ')]"); foreach ($nodes as $node) { $words = explode(' ', $node->nodeValue); $temp = $dom->createElement("p"); $temp->setAttribute("class", "lead"); foreach ($words as $word) { if (ctype_upper($word[0])) { //First char is uppercase $newNode = $dom->createElement('strong', $word . " "); $temp->appendChild($newNode); } else { $newNode = $dom->createTextNode($word . " "); $temp->appendChild($newNode); } } $node->parentNode->replaceChild($temp, $node); } echo $dom->saveHTML(); }
/** * Returns the singular form of a word * * If the method can't determine the form with certainty, an array of the * possible singulars is returned. * * @param string $plural A word in plural form * @return string|array The singular form or an array of possible singular * forms */ public static function singularify($plural) { $pluralRev = strrev($plural); $lowerPluralRev = strtolower($pluralRev); $pluralLength = strlen($lowerPluralRev); // The outer loop $i iterates over the entries of the plural table // The inner loop $j iterates over the characters of the plural suffix // in the plural table to compare them with the characters of the actual // given plural suffix for ($i = 0, $numPlurals = count(self::$pluralMap); $i < $numPlurals; ++$i) { $suffix = self::$pluralMap[$i][self::PLURAL_SUFFIX]; $suffixLength = self::$pluralMap[$i][self::PLURAL_SUFFIX_LENGTH]; $j = 0; // Compare characters in the plural table and of the suffix of the // given plural one by one while ($suffix[$j] === $lowerPluralRev[$j]) { // Let $j point to the next character ++$j; // Successfully compared the last character // Add an entry with the singular suffix to the singular array if ($j === $suffixLength) { // Is there any character preceding the suffix in the plural string? if ($j < $pluralLength) { $nextIsVocal = false !== strpos('aeiou', $lowerPluralRev[$j]); if (!self::$pluralMap[$i][self::PLURAL_SUFFIX_AFTER_VOCAL] && $nextIsVocal) { break; } if (!self::$pluralMap[$i][self::PLURAL_SUFFIX_AFTER_CONS] && !$nextIsVocal) { break; } } $newBase = substr($plural, 0, $pluralLength - $suffixLength); $newSuffix = self::$pluralMap[$i][self::SINGULAR_SUFFIX]; // Check whether the first character in the plural suffix // is uppercased. If yes, uppercase the first character in // the singular suffix too $firstUpper = ctype_upper($pluralRev[$j - 1]); if (is_array($newSuffix)) { $singulars = array(); foreach ($newSuffix as $newSuffixEntry) { $singulars[] = $newBase . ($firstUpper ? ucfirst($newSuffixEntry) : $newSuffixEntry); } return $singulars; } return $newBase . ($firstUpper ? ucFirst($newSuffix) : $newSuffix); } // Suffix is longer than word if ($j === $pluralLength) { break; } } } // Convert teeth to tooth, feet to foot if (false !== ($pos = strpos($plural, 'ee'))) { return substr_replace($plural, 'oo', $pos, 2); } // Assume that plural and singular is identical return $plural; }
public static function isUpperCamelCase($str) { if (!ctype_upper(substr($str, 0, 1))) { return false; } elseif (!ctype_alpha($str)) { return false; } return true; }
/** * @param InputValue $input * @throws ValidationException */ public function process(InputValue $input) { if ($this->getOption('convert') === false && !ctype_upper($input->getValue())) { throw new ValidationException('value must be uppercase'); } $input->replace(function ($value) { return strtoupper($value); }); }
/** * Validate sentence string * * @param string $sentence * @return bool */ private function isValid($sentence) { if (!is_string($sentence) || empty($sentence)) { return false; } $first = substr($sentence, 0, 1); $last = substr($sentence, -1, 1); return ctype_upper($first) || is_numeric($first) && in_array($last, ['.', ';']); }
/** * This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality. * * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method. * @return bool */ protected static function evaluateCondition($arguments = NULL) { if (TRUE === $arguments['fullString']) { $result = ctype_upper($arguments['string']); } else { $result = ctype_upper(substr($arguments['string'], 0, 1)); } return TRUE === $result; }
function removeLastWord($value) { $value = cleanString($value); if (ctype_upper(substr($value, strlen($value) - 1, strlen($value)))) { $value = substr($value, 0, strlen($value) - 1); $value = cleanString($value); } return $value; }
/** * @param string $phone * @param string|NULL $country * @param int|NULL $format * * @return string */ public function phone($phone, $country = 'AUTO', $format = Phone\Phone::FORMAT_INTERNATIONAL) { $country = strtoupper($country); if ((strlen($country) !== 2 || !ctype_alpha($country) || !ctype_upper($country)) && $country !== 'AUTO') { $format = $country; $country = 'AUTO'; } return $this->phone->format($phone, $country, $format); }
/** * Returns the singular form of a word. * * If the method can't determine the form with certainty, an array of the * possible singulars is returned. * * @param string $plural A word in plural form * * @return string|array The singular form or an array of possible singular * forms */ public static function singularify($plural) { $pluralRev = strrev($plural); $lowerPluralRev = strtolower($pluralRev); $pluralLength = strlen($lowerPluralRev); // The outer loop iterates over the entries of the plural table // The inner loop $j iterates over the characters of the plural suffix // in the plural table to compare them with the characters of the actual // given plural suffix foreach (self::$pluralMap as $map) { $suffix = $map[0]; $suffixLength = $map[1]; $j = 0; // Compare characters in the plural table and of the suffix of the // given plural one by one while ($suffix[$j] === $lowerPluralRev[$j]) { // Let $j point to the next character ++$j; // Successfully compared the last character // Add an entry with the singular suffix to the singular array if ($j === $suffixLength) { // Is there any character preceding the suffix in the plural string? if ($j < $pluralLength) { $nextIsVocal = false !== strpos('aeiou', $lowerPluralRev[$j]); if (!$map[2] && $nextIsVocal) { // suffix may not succeed a vocal but next char is one break; } if (!$map[3] && !$nextIsVocal) { // suffix may not succeed a consonant but next char is one break; } } $newBase = substr($plural, 0, $pluralLength - $suffixLength); $newSuffix = $map[4]; // Check whether the first character in the plural suffix // is uppercased. If yes, uppercase the first character in // the singular suffix too $firstUpper = ctype_upper($pluralRev[$j - 1]); if (is_array($newSuffix)) { $singulars = array(); foreach ($newSuffix as $newSuffixEntry) { $singulars[] = $newBase . ($firstUpper ? ucfirst($newSuffixEntry) : $newSuffixEntry); } return $singulars; } return $newBase . ($firstUpper ? ucfirst($newSuffix) : $newSuffix); } // Suffix is longer than word if ($j === $pluralLength) { break; } } } // Assume that plural and singular is identical return $plural; }
/** * Return * @param string $c * @param string $char * @return string */ public static function upperCharByEnotherChar($c = '', $char = '') { if (mb_strlen($char) > 1) { // not throw new Exception but get first char $chars = Utils::str_split_($char); $char = isset($chars[0]) ? $chars[0] : ''; } return $char && ctype_upper($char) ? mb_strtoupper($c) : $c; }
/** * Turn StudlyCase, camelCase, snake_case or kabab-case into a sentence. * * @param string $string * @return string */ function uncase($string) { $snake = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $string)); $sentence = preg_replace('/[-_\\s]+/', ' ', $snake); if (ctype_upper($string[0])) { $sentence = ucfirst($sentence); } return $sentence; }
function numCaps($strArray) { foreach ($strArray as $string) { for ($c = 0; $c < strlen($string); $c++) { $numCaps += ctype_upper($string[$c]) ? 1 : 0; } } return $numCaps; }
/** * Construct a DAO sort option using the columns names or paths used to sort data using current * data link when readAll() and search() * * @example * $option = new Dao_Sort_Option(['first_name', 'last_name', 'city.country.name')); * // Please prefer using this equivalent for standard calls, ie in this standard use example : * $users = Dao::readAll( * 'SAF\Framework\User', * Dao::sort(['first_name', 'last_name', 'city.country.name'))); * ); * * @param $columns string|string[]|Reverse[] a single or several column names, or a class name * to apply each column name can be followed by ' reverse' into the string for reverse order sort * If null, the value of annotations 'sort' or 'representative' of the class will be taken. */ public function __construct($columns = null) { if (is_string($columns) && ctype_upper($columns[0])) { $this->applyClassName($columns); } elseif (isset($columns)) { $this->columns = is_array($columns) ? $columns : [$columns]; $this->calculateReverse(); } }
function chkinput() { global $errors; if (trim($_POST["fname"]) != "") { $name = trim($_POST["fname"]); if (strlen($name) < 21) { $errors[0] = ""; } else { $errors[0] = "<font color='red'>*** Your Firstname has Too many characters? ***</font>"; } } else { $errors[0] = "<font color='red'>*** Your Firstname? ***</font>"; } if (trim($_POST["lname"]) != "") { $name = trim($_POST["lname"]); if (strlen($name) < 21) { $errors[1] = ""; } else { $errors[1] = "<font color='red'>*** Your Lastname has Too many characters? ***</font>"; } } else { $errors[1] = "<font color='red'>*** Your Lastname? ***</font>"; } if (trim($_POST["email"]) != "") { $name = trim($_POST["email"]); if (strlen($name) < 21) { $errors[2] = ""; } else { $errors[2] = "<font color='red'>*** Your E-mail has Too many characters? ***</font>"; } } else { $errors[2] = "<font color='red'>*** Your E-mail? ***</font>"; } if (trim($_POST["password"]) != "") { $pass = trim($_POST["password"]); if (strlen($pass) == 7) { if (!is_numeric($pass)) { if (ctype_alpha(substr($pass, 0, 1)) && ctype_alnum(substr($pass, 0, 1))) { for ($i = 0; $i < strlen($pass); $i++) { $passlt = substr($pass, $i, 1); if (!is_numeric($passlt) && ctype_upper($passlt)) { $errors[3] = "<font color='red'>*** Invalid Characters ***</font>"; break; } } } } else { $errors[3] = "<font color='red'>*** Your Password Cannot be numeric ***</font>"; } } else { $errors[3] = "<font color='red'>*** Your Password MUST be 7 characters? ***</font>"; } } else { $errors[3] = "<font color='red'>*** Your Password? ***</font>"; } }
/** * @param string $str * @return string[] */ function splitStringOnUpperCase($str) { $ret = array(); if (!ctype_upper($str)) { return preg_split('/(?=[A-Z])/', $str, -1, PREG_SPLIT_NO_EMPTY); } else { $ret[] = $str; } return $ret; }
public static function isCamelUpper($symbol) { $arr = explode('_', $symbol); foreach ($arr as $temp) { if (!ctype_upper($temp)) { return false; } } return true; }
public function __get($name) { $fc = substr($name, 0, 1); if (ctype_upper($fc)) { $model = $this->Model($name); if ($model) { return $this->{$name} = $model; } } }
function crawl($url, $path, $website, $rec, $lang) { $html = file_get_html($url); $data = $html->find('div[id=bodyContent] p'); $count = 0; $count2 = 0; $p = parse_url($url); foreach ($data as $i) { $para = strip_tags($i->innertext); $no_bracket = preg_replace("/\\([^)]+\\)/", '', $para); $no_bracket = preg_replace("/\\[[^)]+\\]/", '', $no_bracket); $re = '/# Split sentences on whitespace between them. (?<= # Begin positive lookbehind. [.!?] # Either an end of sentence punct, | [.!?][\'"] # or end of sentence punct and quote. ) # End positive lookbehind. (?<! # Begin negative lookbehind. Mr\\. # Skip either "Mr." | Mrs\\. # or "Mrs.", | Ms\\. # or "Ms.", | Jr\\. # or "Jr.", | Dr\\. # or "Dr.", | Prof\\. # or "Prof.", | Sr\\. # or "Sr.", | T\\.V\\.A\\. # or "T.V.A.", | St\\. # or "T.V.A.", | \\s[A-Z]\\. # or initials ex: "George W. Bush", # or... (you get the idea). ) # End negative lookbehind. \\s+ # Split on whitespace between sentences. /ix'; $sentences = preg_split($re, $no_bracket, -1, PREG_SPLIT_NO_EMPTY); foreach ($sentences as $sentence) { if (strlen($sentence) > 10 && !strpos($sentence, ':') && (ctype_upper($sentence[0]) || ctype_digit($sentence[0]))) { add_sentence($sentence, $lang); $count++; } } } $data = $html->find('a'); $count2 = 0; $url = ""; foreach ($data as $i) { if (startsWith($i->href, '/wiki/') && !strpos($i->href, ':')) { if (strpos($i->href, '#') > 0) { $i->href = substr($i->href, 0, strpos($i->href, '#')); } // echo "http://".$p["host"].$i->href."<br/>"; add_url("http://" . $p["host"] . $i->href, $website, 3, $rec); $count2++; } } echo $count . " sentences have been added from URL : " . $url . "<br/>"; echo $count2 . " links have been added from URL : " . $url; }