本文整理汇总了PHP中Nette\Utils\Strings::replace方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::replace方法的具体用法?PHP Strings::replace怎么用?PHP Strings::replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Strings
的用法示例。
在下文中一共展示了Strings::replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderPairMulti
public function renderPairMulti(array $controls)
{
$rendered = parent::renderPairMulti($controls);
$class = $this->getValue('control .buttons');
$firstReplace = Nette\Utils\Strings::replace($rendered, '~(form-group">\\s*<div) class="~', "\\0{$class} ");
return Nette\Utils\Strings::replace($firstReplace, '~(form-group">\\s*<div)>~', "\\1 class=\"{$class}\">");
}
示例2: priceCreate
/**
* @param double|double[] $price
* @param null|string $units
* @param int $decimalLength
*
* @return string|string[]
*/
public static function priceCreate($price, $units = NULL, $decimalLength = 2)
{
if (is_array($price)) {
$out = [];
foreach ($price as $v) {
$out[] = static::priceCreate($v, $units, $decimalLength);
}
return $out;
} else {
$workPrice = floor(abs($price * pow(10, $decimalLength)));
$workDecimalPrice = floor(abs($price * pow(10, $decimalLength + 1)));
$integerPrice = floor($workPrice / pow(10, $decimalLength));
$integerLength = strlen($integerPrice);
$decimalPrice = Nette\Utils\Strings::padLeft(round(static::numberAt($workDecimalPrice, 0, $decimalLength + 1) / 10), $decimalLength, '0');
$integerTernary = ceil($integerLength / 3);
$outPrice = '';
for ($i = $integerTernary - 1; $i >= 0; $i--) {
if ($outPrice != "") {
$outPrice .= '.';
}
$outPrice .= Nette\Utils\Strings::padLeft(static::numberAt($integerPrice, $i * 3, 3), 3, '0');
}
$outPrice = Nette\Utils\Strings::replace($outPrice, ['~^[0]*~' => '']);
return ($price < 0 ? '-' : '') . $outPrice . ',' . (in_array($decimalPrice, ['', '0']) ? '-' : $decimalPrice) . (is_null($units) ? '' : ' ' . $units);
}
}
示例3: formatRecordString
public static function formatRecordString($record, $formatString)
{
return Strings::replace($formatString, '#%[^%]*%#u', function ($m) use($record) {
$m = Strings::trim($m[0], '%');
return $m != '' ? $record[$m] : "%";
});
}
示例4: computeHash
/**
* @param string|array $file
* @param int $time
* @param bool $debugMode
*
* @return string
*/
public static function computeHash($file, $time, $debugMode)
{
$debug = $debugMode ? 1 : 0;
$file = is_array($file) ? implode(',', $file) : $file;
$md5Raw = md5("{$debug};{$file};{$time}", TRUE);
$base64 = Strings::replace(base64_encode($md5Raw), '~\\W~');
return Strings::substring(Strings::webalize($base64), 0, 8);
}
示例5: macroSet
public function macroSet(MacroNode $node, PhpWriter $writer)
{
$parts = Strings::replace($node->args, '~(\\s*(=>|=)\\s*|\\s+)~', '~~~', 1);
$parts = Strings::split($parts, '/~~~/');
$variable = $parts[0];
$rest = $parts[1];
return $writer->write($variable . ' = %modify(' . $rest . ')');
}
示例6: formatTemplateFiles
/**
* Formats view template file names.
*
* @param string $subMethod
* @return array
*/
protected function formatTemplateFiles($subMethod)
{
$controlName = $this->getReflection()->getShortName();
$control = Strings::replace($controlName, '~Control$~');
$dir = dirname($this->getReflection()->getFileName());
$dir = is_dir("{$dir}/templates") ? $dir : dirname($dir);
$view = $subMethod ?: 'default';
return ["{$dir}/templates/{$control}/{$view}.latte", "{$dir}/templates/{$control}.{$view}.latte"];
}
示例7: formatLikeStatementWildcards
/**
* Format given value for LIKE statement
*
* @param string $value
* @param string $replacement
* @return string
*/
public static function formatLikeStatementWildcards($value, $replacement = '%')
{
// Escape wildcard character used in PDO
$value = str_replace($replacement, '\\' . $replacement, $value);
// Replace asterisks
$value = \Nette\Utils\Strings::replace($value, '~(?!\\\\)(.?)\\*~', '\\1' . $replacement);
// Replace escaped asterisks
return str_replace('\\*', '*', $value);
}
示例8: inflect
/**
*
* @param string $word
* @param string $genus (rod)
* @param string $number (číslo - jednotné nebo množné)
* @param string $case (pád)
* @return string
*/
public function inflect($word, $genus = 'n', $number = 's', $case = 'nom')
{
foreach ($this->dictionary as $key => $shapes) {
if (Strings::match($word, $key) && isset($this->dictionary[$key][$genus][$number][$case])) {
$inflectedWord = Strings::replace($word, $key, $shapes[$genus][$number][$case]);
return $inflectedWord;
}
}
return $inflectedWord;
}
示例9: __invoke
/**
* Invoke filter
*
* @param string code
* @param WebLoader loader
* @param string file
* @return string
*/
public function __invoke($code, \Lohini\WebLoader\WebLoader $loader, $file = NULL)
{
$regexp = '/@charset ["\']utf\\-8["\'];(\\n)?/i';
$removed = Strings::replace($code, $regexp);
// At least one charset was in the code
if (Strings::length($removed) < Strings::length($code)) {
$code = self::CHARSET . "\n" . $removed;
}
return $code;
}
示例10: reformatMarkdownLinks
/**
* @param Github $github
*/
protected function reformatMarkdownLinks(Github $github)
{
$github->content = Strings::replace($github->content, '#\\[(.*)\\]\\((.+)\\)#iU', function ($matches) use($github) {
list($all, $title, $url) = $matches;
if (!Validators::isUrl($url)) {
$url = $github->linker->getBlobUrl($matches[2]);
}
return sprintf('[%s](%s)', $title, $url);
});
}
示例11: formatColumnName
/**
* Formats column name.
* @param string
* @return string
*/
public function formatColumnName($key)
{
static $cache = array();
$name =& $cache[$key];
if ($name === NULL) {
$name = Strings::replace($key, '#[A-Z]#', function ($match) {
return '_' . strtolower($match[0]);
});
}
return $name;
}
示例12: doRender
/**
* @param string name of current render method, typically __METHOD__ (containing "ClassName::render")
* @return void
*/
protected function doRender($renderMethod)
{
$template = $this->getTemplate();
$classFile = $this->getReflection()->getFileName();
list(, $view) = Strings::match($renderMethod, '~::render(.*)\\z~');
$templateFile = Strings::replace($classFile, '~(?<=/)(.+)\\.php\\z~i', function ($m) use($view) {
return $m[1] . ($view ? ".{$view}" : '') . '.latte';
});
$template->setFile($templateFile);
$template->render();
}
示例13: startup
public function startup()
{
parent::startup();
$this->template->addFilter("dicomString", function ($text) {
return \Nette\Utils\Strings::replace($text, "/\\^/", " ");
});
$this->template->addFilter("dicomDate", function ($text) {
return date("d-m-Y", strtotime($text));
});
return;
}
示例14: lex
/**
* @param string $config
* @return TokenIterator tokens
* @throws ConfigException
*/
public function lex($config)
{
$normalized = Strings::normalize($config);
// remove meaningless leading spacing to simplify T_KEYWORD
$simplified = Strings::replace($normalized, '~^\\s+~m', '');
try {
$tokens = $this->getTokenizer()->tokenize($simplified);
return new TokenIterator($tokens);
} catch (TokenizerException $e) {
throw ConfigException::createFromLexerException($e);
}
}
示例15: expandPath
/**
* Expands @fooModule/path/....
* @static
* @param $path
* @param array $modules
* @return string
* @throws InvalidArgumentException
*/
public function expandPath($path, $localPrefix = '')
{
if (substr($path, 0, 1) !== '@' || ($pos = strpos($path, 'Module')) === FALSE) {
return $path;
}
$module = lcfirst(substr($path, 1, $pos - 1));
if (!isset($this->modules[$module])) {
throw new InvalidArgumentException("Module '{$module}' does not exist.");
}
$path = $this->modules[$module]['path'] . ($localPrefix ? '/' . $localPrefix : '') . substr($path, $pos + 6);
return \Nette\Utils\Strings::replace($path, '~\\\\~', '/');
}