本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例6: is_anagram
function is_anagram($a, $b)
{
if (count_chars($a, 1) == count_chars($b, 1)) {
return "1";
}
return '0';
}
示例7: countChars
private function countChars($data)
{
foreach (count_chars($data, 1) as $char => $count) {
$this->charCount[chr($char)] = $count;
}
$this->sortChars($this->charCount);
}
示例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;
}
示例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;
}
示例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}";
}
示例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;
}
示例12: arrayLetraCount
function arrayLetraCount($str)
{
$tengo = array();
foreach (count_chars($str, 1) as $i => $val) {
$tengo[chr($i)] = $val;
}
return $tengo;
}
示例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);
}
示例14: countchars_b
function countchars_b($v)
{
foreach (count_chars($v, 1) as $i => $val) {
$res += $val;
}
//chr($i)
return $res;
}
示例15: getCharactersNumber
function getCharactersNumber($message)
{
$result = 0;
foreach (count_chars($message, 0) as $i => $val) {
$result += $i !== 32 ? $val : 0;
}
return $result;
}