当前位置: 首页>>代码示例>>PHP>>正文


PHP count_chars函数代码示例

本文整理汇总了PHP中count_chars函数的典型用法代码示例。如果您正苦于以下问题:PHP count_chars函数的具体用法?PHP count_chars怎么用?PHP count_chars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了count_chars函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findWord

/**
 * findWord
 *
 * Compute the word that contains the highest number of repeated charaters
 * from the supplied text file
 *
 * @param  string $filePath The search text
 * @return string       The word with the highest number of charaters
 */
function findWord($filePath)
{
    if (!is_readable($filePath)) {
        throw new \RuntimeException(sprintf('The file path \'%s\' is not readable.', $filePath));
    }
    $text = file_get_contents($filePath);
    if (false === $text) {
        throw new \RuntimeException(sprintf('An error occured while trying to read the contents of \'%s\'', $filePath));
    }
    if (empty($text)) {
        throw new \DomainException(sprintf('The text file \'%s\' contains no text!', $filePath));
    }
    $winningWord = null;
    $charCount = 0;
    foreach (str_word_count(strtolower($text), 1) as $word) {
        $counts = count_chars($word, 1);
        if (!empty($counts)) {
            rsort($counts);
            $count = current($counts);
            if ($charCount == 0 || $count > $charCount) {
                $winningWord = $word;
                $charCount = $count;
            }
        }
    }
    return $winningWord;
}
开发者ID:alex-patterson-webdev,项目名称:arp-word-match,代码行数:36,代码来源:findword.php

示例2: replyTable

 /**
  * Reply to the current origin and user, display as a table
  * @todo Write a class that can display ascii art tables and stuff.
  * @author digitalseraphim
  * @since Shadowlamb 3.1
  * @param array $table where each entry is 'row label' => array(values)
  * @return true|false
  */
 public function replyTable(array $table, $langkey = '5044')
 {
     $maxRowLabelWidth = 0;
     $maxWidths = array(-1 => 0);
     foreach ($table as $key => $value) {
         $maxWidths[-1] = max($maxWidths[-1], strlen($key));
         foreach ($value as $k => $v) {
             $charcounts = count_chars($v, 0);
             $vlen = strlen($v) - $charcounts[2];
             if (!array_key_exists($k, $maxWidths)) {
                 $maxWidths[$k] = $vlen;
             } else {
                 $maxWidths[$k] = max($maxWidths[$k], $vlen);
             }
         }
     }
     foreach ($table as $key => $value) {
         $s = sprintf('%-' . ($maxWidths[-1] + 1) . 's', $key);
         foreach ($value as $k => $v) {
             $charcounts = count_chars($v, 0);
             $s .= sprintf('| %-' . ($maxWidths[$k] + 1 + $charcounts[2]) . 's', $v);
         }
         $this->reply(Shadowrun4::lang($langkey, array($s)));
         // 			$this->reply($s);
     }
 }
开发者ID:sinfocol,项目名称:gwf3,代码行数:34,代码来源:Shadowrap.php

示例3: install

 /**
  * sp_Installer::install() - this method performs the installation of SubjectsPlus
  *
  * @return boolean
  */
 public function install()
 {
     $db = new Querier();
     foreach ($this->lobjCreateQueries as $lstrCQuery) {
         if ($db->exec($lstrCQuery) === FALSE) {
             var_dump($db->errorInfo());
             $this->displayInstallationErrorPage(_("Problem creating new table."));
             return FALSE;
         }
     }
     foreach ($this->lobjInsertQueries as $lstrIQuery) {
         if ($db->exec($lstrIQuery) === FALSE) {
             $this->displayInstallationErrorPage(_("Problem inserting new data into table."));
             $error_info = $db->errorInfo();
             if (count_chars($error_info[2]) > 0) {
                 var_dump($db->errorInfo());
                 echo $lstrIQuery;
             }
             return FALSE;
         }
     }
     if (!$this->updateRewriteBases()) {
         return FALSE;
     }
     return TRUE;
 }
开发者ID:johnwinsor,项目名称:SubjectsPlus,代码行数:31,代码来源:Installer.php

示例4: process

 public function process($str)
 {
     $str = $this->prepareString($str);
     $this->analysis = array();
     switch ($this->analysis_type) {
         case Cryptography::SCOPE_LETTER:
             $res = count_chars($str, 1);
             foreach ($res as $i => $v) {
                 $this->analysis[chr($i)] = $v;
             }
             break;
         case Cryptography::SCOPE_WORD:
             $parts = explode(' ', $str);
             foreach ($parts as $part) {
                 if (!array_key_exists($part, $this->analysis)) {
                     $this->analysis[$part] = substr_count($str, $part);
                 }
             }
             break;
         case Cryptography::SCOPE_RANDOM:
             break;
     }
     uasort($this->analysis, function ($a, $b) {
         return $a > $b ? -1 : ($a == $b ? 0 : 1);
     });
     return $this;
 }
开发者ID:atelierspierrot,项目名称:cryptography,代码行数:27,代码来源:Frequency.php

示例5: calculateFloor

 /**
  * Follows the instructions to calculate the floor reached by Santa
  *
  * @param string $instructions The instructions to use for the calculation
  * @return int The floor that has been reached
  */
 public static function calculateFloor($instructions)
 {
     $tokens = count_chars($instructions, 1);
     $ups = (isset($tokens[self::GO_UP]) ? $tokens[self::GO_UP] : 0) * 1;
     $downs = (isset($tokens[self::GO_DOWN]) ? $tokens[self::GO_DOWN] : 0) * -1;
     return $ups + $downs;
 }
开发者ID:rogamoore,项目名称:advent-of-code-2015,代码行数:13,代码来源:Day1.php

示例6: is_anagram

function is_anagram($a, $b)
{
    if (count_chars($a, 1) == count_chars($b, 1)) {
        return "1";
    }
    return '0';
}
开发者ID:Pandafuchs,项目名称:codingame,代码行数:7,代码来源:checkIfAnagram.php

示例7: countChars

 private function countChars($data)
 {
     foreach (count_chars($data, 1) as $char => $count) {
         $this->charCount[chr($char)] = $count;
     }
     $this->sortChars($this->charCount);
 }
开发者ID:bryantlee,项目名称:public,代码行数:7,代码来源:fogcreek.php

示例8: match

 public function match(&$collection, $needle, $tolerance)
 {
     $best = $tolerance;
     $match = '';
     $needle_chars = count_chars($needle);
     foreach ($collection as $userAgent) {
         $ua_chars = count_chars($userAgent);
         $sum = 0;
         $can_apply_ld = true;
         //Check from 32 (space) to 122 ('z')
         for ($i = 32; $i < 122; $i++) {
             $sum += abs($needle_chars[$i] - $ua_chars[$i]);
             if ($sum > 2 * $tolerance) {
                 $can_apply_ld = false;
                 break;
             }
         }
         if ($can_apply_ld === true) {
             $current = levenshtein($needle, $userAgent);
             if ($current <= $best) {
                 $best = $current - 1;
                 $match = $userAgent;
             }
         }
     }
     return $match;
 }
开发者ID:conversionstudio,项目名称:cpatracker,代码行数:27,代码来源:LDMatcher.php

示例9: compose

 function compose($o)
 {
     if ($this->debug || $this->get->src) {
         $o = parent::compose($o);
         $o->cookie_path = $CONFIG['session.cookie_path'];
         $o->cookie_domain = $CONFIG['session.cookie_domain'];
         $o->document_domain = $CONFIG['document.domain'];
         $o->maxage = $CONFIG['maxage'];
     } else {
         ++self::$recursion;
         $src = Patchwork\Superloader::class2file(substr(get_class($this), 6));
         $src = Patchwork\Serverside::returnAgent($src, (array) $this->get);
         --self::$recursion;
         $parser = new JSqueeze();
         if ('/*!' != substr(ltrim(substr($src, 0, 512)), 0, 3)) {
             $o->DATA = Patchwork::__URI__();
             $o->DATA .= (false === strpos($o->DATA, '?') ? '?' : '&') . 'src=1';
             $o->DATA = "// Copyright & source: {$o->DATA}\n";
             foreach (count_chars($o->DATA, 1) as $k => $w) {
                 $parser->charFreq[$k] += $w;
             }
             $o->DATA .= $parser->squeeze($src);
         } else {
             $o->DATA = $parser->squeeze($src);
         }
     }
     return $o;
 }
开发者ID:nicolas-grekas,项目名称:Patchwork,代码行数:28,代码来源:js.php

示例10: runIndentationLoop

 function runIndentationLoop()
 {
     $lines = explode("\n", $this->body);
     $previousSelector = '';
     $pastLevel = 0;
     $this->body = '';
     foreach ($lines as $key => $line) {
         if (eregi('([a-z]+)\\:', $line)) {
             //Rule
             $this->body .= "\n\t" . trim($line) . ';';
         } elseif (eregi('(\\t*)[\\.a-z]', $line)) {
             // Selector
             if ($previousSelector) {
                 $this->body .= "\n}\n";
             }
             //echo $line."\n";
             $charCount = count_chars($line, 1);
             if (eregi('&', $line)) {
                 $pastLevel = $charCount[9];
                 $this->body .= str_replace('&', trim($previousSelector), trim($line)) . ' {';
             } else {
                 if ($charCount[9] > $pastLevel) {
                     $pastLevel = $pastLevel + 1;
                     $this->body .= eregi('(\\t*)\\:', $line) ? $previousSelector : $previousSelector . ' ';
                     $this->body .= trim($line) . ' {';
                 } else {
                     $this->body .= trim($line) . ' {';
                 }
             }
             $previousSelector = trim($line);
         }
     }
     $this->body .= "\n}";
 }
开发者ID:stuartloxton,项目名称:php-saas,代码行数:34,代码来源:php-saas.php

示例11: getRandomString

 /**
  * Create a random string composed of a characters.
  * $length - The number of random strings to include in the result.
  *
  * @param int    $length
  * @param string $charset
  *
  * @throws \InvalidArgumentException If the charset is invalid or if the length is less than 1.
  *
  * @return string
  */
 public static function getRandomString($length, $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~+/')
 {
     self::checkLength($length);
     $charset = count_chars($charset, 3);
     self::checkCharset($charset);
     $characterSet = str_split($charset);
     $charSetLen = count($characterSet);
     $random = self::getRandomInts($length * 2);
     $mask = self::getMinimalBitMask($charSetLen - 1);
     $password = '';
     $iterLimit = max($length, $length * 64);
     // If length is close to PHP_INT_MAX we don't want to overflow.
     $randIdx = 0;
     while (self::safeStringLength($password) < $length) {
         if ($randIdx >= count($random)) {
             $random = self::getRandomInts(2 * ($length - self::safeStringLength($password)));
             $randIdx = 0;
         }
         // This is wasteful, but RNGs are fast and doing otherwise adds complexity and bias.
         $c = $random[$randIdx++] & $mask;
         // Only use the random number if it is in range, otherwise try another (next iteration).
         if ($c < $charSetLen) {
             $password .= self::sideChannelSafeArrayIndex($characterSet, $c);
         }
         // Guarantee termination
         $iterLimit--;
         if ($iterLimit <= 0) {
             throw new \RuntimeException('Hit iteration limit when generating password.');
         }
     }
     return $password;
 }
开发者ID:spomky-labs,项目名称:defuse-generator,代码行数:43,代码来源:DefuseGenerator.php

示例12: arrayLetraCount

function arrayLetraCount($str)
{
    $tengo = array();
    foreach (count_chars($str, 1) as $i => $val) {
        $tengo[chr($i)] = $val;
    }
    return $tengo;
}
开发者ID:ricardclau,项目名称:tuenti-contest,代码行数:8,代码来源:test11.php

示例13: stringorder

 public function stringorder($string)
 {
     if (preg_match('/[^a-zA-Z\\s-]/i', $string)) {
         abort(404, "Inputan Salah");
     }
     $sortnya = count_chars($string, 3);
     return trim($sortnya);
 }
开发者ID:imamramadhan19,项目名称:latihan-php-unit,代码行数:8,代码来源:Sortalphabet.php

示例14: countchars_b

function countchars_b($v)
{
    foreach (count_chars($v, 1) as $i => $val) {
        $res += $val;
    }
    //chr($i)
    return $res;
}
开发者ID:philum,项目名称:cms,代码行数:8,代码来源:indent.php

示例15: getCharactersNumber

function getCharactersNumber($message)
{
    $result = 0;
    foreach (count_chars($message, 0) as $i => $val) {
        $result += $i !== 32 ? $val : 0;
    }
    return $result;
}
开发者ID:PierreCharles,项目名称:Sockets-Project,代码行数:8,代码来源:index.php


注:本文中的count_chars函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。