本文整理汇总了PHP中Nette\Utils\Strings::toAscii方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::toAscii方法的具体用法?PHP Strings::toAscii怎么用?PHP Strings::toAscii使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Strings
的用法示例。
在下文中一共展示了Strings::toAscii方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compute
public function compute($password, User $user)
{
$fields = ['name', 'email', 'familyName', 'firstName'];
$parts = [];
$index = 1;
foreach ($fields as $field) {
foreach (preg_split('~[@._\\s+]~', $user->{$field}) as $part) {
$parts[$part] = $index++;
$parts[Strings::toAscii($part)] = $index++;
}
}
try {
$result = $this->computer->passwordStrength($password, $parts);
} catch (\Exception $e) {
return NULL;
}
return number_format($result['entropy'], 2);
}
示例2: filterData
private function filterData()
{
foreach ($this->data as $id => $item) {
$value = array();
$match = true;
foreach ($this->filter[1] as $collumn) {
$value[$collumn] = strtolower(Strings::toAscii($item[$collumn]));
}
foreach ($this->filter[0] as $word) {
$found = false;
foreach ($value as $val) {
if (strstr($val, $word) !== false) {
$found = true;
break;
}
}
if (!$found) {
$match = false;
break;
}
}
if (!$match) {
unset($this->data[$id]);
}
}
}
示例3: compare
/**
* @param string $actual
* @param string $condition
* @param mixed $expected
* @throws Exception
* @return bool
*/
public function compare($actual, $condition, $expected)
{
$expected = (array) $expected;
$expected = current($expected);
$cond = str_replace(' ?', '', $condition);
if ($cond === 'LIKE') {
$actual = Strings::toAscii($actual);
$expected = Strings::toAscii($expected);
$pattern = str_replace('%', '(.|\\s)*', preg_quote($expected, '/'));
return (bool) preg_match("/^{$pattern}\$/i", $actual);
} elseif ($cond === '=') {
return $actual == $expected;
} elseif ($cond === '<>') {
return $actual != $expected;
} elseif ($cond === 'IS NULL') {
return $actual === NULL;
} elseif ($cond === 'IS NOT NULL') {
return $actual !== NULL;
} elseif ($cond === '<') {
return (int) $actual < $expected;
} elseif ($cond === '<=') {
return (int) $actual <= $expected;
} elseif ($cond === '>') {
return (int) $actual > $expected;
} elseif ($cond === '>=') {
return (int) $actual >= $expected;
} else {
throw new Exception("Condition '{$condition}' not implemented yet.");
}
}
示例4: createProject
/**
* @param type $name
* @param \User $user
* @return \Project
* @throws \ExistingProjectException
*/
public function createProject($values, \User $user)
{
$project = new \Project();
$key = $this->keyGenerator->generateKey();
$name = Strings::webalize(Strings::lower(Strings::toAscii($values->caption)));
$name = str_replace('-', '_', $name);
$project->setCaption($values->caption)->setName($name)->setSourceLanguage($values->sourceLang)->setLink($values->link)->setKey($key);
$project->setOwner($user);
$this->dm->persist($project);
$this->dm->flush();
return $project;
}
示例5: search
public function search($query, $excludeIds = null)
{
$query = \Nette\Utils\Strings::toAscii($query);
$regex = new \MongoRegex('/.*' . $query . '.*/i');
$qb = $this->dm->getRepository('User')->createQueryBuilder()->field('nick')->equals($regex);
//->field('email')->equals($regex);
//$qb->addOr($qb->field('nick')->equals($regex));
$qb->addOr($qb->expr()->field('email')->equals($regex));
if ($excludeIds !== null) {
$qb->field('id')->notIn($excludeIds);
}
$qb->sort('nick', 'desc');
return $qb->getQuery()->execute();
}
示例6: save
public function save($sourceFile, $originalName, $path, $thumbs = array())
{
if (!file_exists($this->root)) {
throw new \Nette\IOException("FileBackend root doesn't exists '{$this->root}'");
}
if (!file_exists($sourceFile)) {
throw new \Nette\IOException("Source file '{$sourceFile}' doesn't exists ");
}
FileSystem::createDir($this->root . $path);
$originalName = Strings::toAscii($originalName);
$targetFile = $path . DIRECTORY_SEPARATOR . $originalName;
$targetFullPath = $this->root . $targetFile;
FileSystem::copy($sourceFile, $targetFullPath);
foreach ($thumbs as $thumb => $thumbPath) {
if (!file_exists($thumbPath)) {
throw new \Nette\IOException("Thumb doesn't exists '{$thumbPath}'");
}
$targetThumbPath = $this->root . $path . DIRECTORY_SEPARATOR . $thumb . '_' . $originalName;
FileSystem::copy($thumbPath, $targetThumbPath);
}
return $path . DIRECTORY_SEPARATOR . $originalName;
}
示例7: morse
/**
* Czech helper translate to morse code.
*
* @param string Message to be translated
* @param bool Do you want to change numbers to words
* @return string Encoded message
*/
public static function morse($text, $number = TRUE)
{
//prepare text for translation
$morseText = \Nette\Utils\Strings::normalize($text);
$morseText = \Nette\Utils\Strings::toAscii($morseText);
$morseText = \Nette\Utils\Strings::lower($morseText);
if ($number) {
foreach (self::$NUMBERS as $original => $translation) {
//translate numbers to text
$morseText = str_replace($original, $translation, $morseText);
}
//remove double spaces
$morseText = \Nette\Utils\Strings::replace($morseText, '/ {2,}/', ' ');
$morseText = \Nette\Utils\Strings::normalize($morseText);
}
foreach (self::$TRANSLATOR as $original => $translation) {
//translate text to morse code
$morseText = str_replace($original, $translation, $morseText);
}
$morseText = '///' . $morseText . '//';
//start & end of text
return $morseText;
}
示例8: renderDefault
public function renderDefault($search)
{
//FIXME tagy ::: 'publish_date <=' => new \DateTime()
$string = Strings::lower(Strings::normalize($search));
$string = Strings::replace($string, '/[^\\d\\w]/u', ' ');
$words = Strings::split(Strings::trim($string), '/\\s+/u');
$words = array_unique(array_filter($words, function ($word) {
return Strings::length($word) > 1;
}));
$words = array_map(function ($word) {
return Strings::toAscii($word);
}, $words);
$string = implode(' ', $words);
$this->template->tag = $this->tags->findOneBy(['name' => $string]);
$result = $this->posts->fulltextSearch($string);
if (count($result) == 0) {
$this->template->search = $search;
$this->template->error = 'Nic nebylo nalezeno';
} else {
$this->template->search = $search;
$this->template->result = $result;
}
}
示例9: organizationFormSucceded
/**
* Processing of organization member editation form
*
* @Privilege("edit", "create")
*
* @param Form $form
*/
public function organizationFormSucceded(Form $form)
{
$values = $form->getValues(TRUE);
unset($values['send']);
//handle file upload
$file = $values['file'];
unset($values['file']);
$params = $this->context->parameters;
$path = $params['wwwDir'] . $params['memberPhotosStorage'] . '/';
if ($file->isOk()) {
if ($file->isImage()) {
//make sure the file will be JPEG
$image = $file->toImage();
$filename = \Nette\Utils\Strings::lower(\Nette\Utils\Strings::toAscii($values['nickname'])) . ".jpg";
$image->save($path . $filename, 100, \Nette\Image::JPEG);
}
}
$item = $this->members->get($values['nickname']);
if ($item) {
$item->update($values);
$this->flashMessage('Záznam byl úspěšně aktualizován');
} else {
$this->members->insert($values);
$this->flashMessage('Záznam byl úspěšně vytvořen');
}
$this->redirect('default');
}
示例10: safeFilename
/**
* Get safe file name
*
* @param string $name File name
*
* @return string
*/
public function safeFilename($name)
{
$except = array("\\", "/", ":", "*", "?", '"', "<", ">", "|");
$name = str_replace($except, "", $name);
return Strings::toAscii($name);
}
示例11: processStorePath
private function processStorePath($storePath, $tmpFileName)
{
$replace = array(':year' => date('Y'), ':month' => date('m'), ':day' => date('d'), ':hash' => md5($tmpFileName . time() . Random::generate(32)), ':filename' => Strings::toAscii($tmpFileName));
return str_replace(array_keys($replace), array_values($replace), $storePath);
}
示例12: hash
public static function hash($input)
{
$hash = Strings::toAscii($input);
$hash = Str_Replace(' ', '', $hash);
$hash = md5($hash);
return $hash . '-' . base64_encode($input);
}
示例13: getWordVariations
public function getWordVariations($word)
{
$sNoBrackets = Strings::replace($word, "/[\\[\\](){}]/", "");
$keywords = array_merge(array($word, $sNoBrackets), explode("-", $sNoBrackets), explode("_", $sNoBrackets), explode(" ", $sNoBrackets), Strings::split($sNoBrackets, "[ _-]"));
foreach ($keywords as $index => $kw) {
$keywords[$index] = Strings::trim($kw);
$keywords[$index] = Strings::replace($keywords[$index], '/^\\+/', '');
// remove + operator
if (Strings::length($keywords[$index]) < 3) {
unset($keywords[$index]);
} else {
$keywords[] = Strings::toAscii($keywords[$index]);
}
}
$keywords = array_unique($keywords);
$keywords = array_values($keywords);
return $keywords;
}
示例14: applyFilter
/**
* Apply fitler and tell whether row passes conditions or not
* @param mixed $row
* @param Filter $filter
* @return mixed
*/
protected function applyFilter($row, Filter $filter)
{
if (is_array($row) || $row instanceof \Traversable) {
if ($filter instanceof FilterDate) {
return $this->applyFilterDate($row, $filter);
} else {
if ($filter instanceof FilterMultiSelect) {
return $this->applyFilterMultiSelect($row, $filter);
} else {
if ($filter instanceof FilterDateRange) {
return $this->applyFilterDateRange($row, $filter);
} else {
if ($filter instanceof FilterRange) {
return $this->applyFilterRange($row, $filter);
}
}
}
}
$condition = $filter->getCondition();
foreach ($condition as $column => $value) {
if ($filter instanceof FilterText && $filter->isExactSearch()) {
return $row[$column] == $value;
}
if ($filter instanceof FilterText && $filter->hasSplitWordsSearch() === FALSE) {
$words = [$value];
} else {
$words = explode(' ', $value);
}
$row_value = strtolower(Strings::toAscii($row[$column]));
foreach ($words as $word) {
if (FALSE !== strpos($row_value, strtolower(Strings::toAscii($word)))) {
return $row;
}
}
}
}
return FALSE;
}
示例15: applyFilter
/**
* Apply fitler and tell whether row passes conditions or not
* @param mixed $row
* @param Filter $filter
* @return mixed
*/
protected function applyFilter($row, Filter $filter)
{
if (is_array($row) || $row instanceof \Traversable) {
if ($filter instanceof FilterDate) {
return $this->applyFilterDate($row, $filter);
}
$condition = $filter->getCondition();
foreach ($condition as $column => $value) {
$words = explode(' ', $value);
$row_value = strtolower(Strings::toAscii($row[$column]));
foreach ($words as $word) {
if (FALSE !== strpos($row_value, strtolower(Strings::toAscii($value)))) {
return $row;
}
}
}
}
return FALSE;
}