本文整理汇总了PHP中Nette\Utils\Strings::trim方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::trim方法的具体用法?PHP Strings::trim怎么用?PHP Strings::trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Strings
的用法示例。
在下文中一共展示了Strings::trim方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sanitize
/**
* Filter: removes unnecessary whitespace and shortens value to control's max length.
*
* @return string
*/
public function sanitize($value)
{
if ($this->control->maxlength && Nette\Utils\Strings::length($value) > $this->control->maxlength) {
$value = Nette\Utils\Strings::substring($value, 0, $this->control->maxlength);
}
return Nette\Utils\Strings::trim(strtr($value, "\r\n", ' '));
}
示例2: 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] : "%";
});
}
示例3: parse
private function parse($link)
{
$data = $this->toUtf8(file_get_contents(str_replace("&", "&", $this->url . $link)));
if (preg_match_all("/<div class=\"wrn2\">.*<\\/div>/", $data, $match) !== 0) {
return FALSE;
}
preg_match_all("/<td align=\"left\" valign=\"top\" width=\"20%\"> <span class=\"tl\">Obchodné meno: <\\/span><\\/td>\\s*<td align=\"left\" width=\"80%\"><table width=\"100%\" border=\"0\">\\s*<tr>\\s*<td width=\"67%\"> <span class='ra'>(?<name>[^<]*)<\\/span><br><\\/td>\\s*<td width=\"33%\" valign='top'> <span class='ra'>\\(od: \\d{2}\\.\\d{2}\\.\\d{4}\\)<\\/span><\\/td>\\s*<\\/tr>\\s*<\\/table><\\/td>\\s*<\\/tr>\\s*<\\/table>\\s*<table width=\"100%\" border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"0\" bgcolor='#ffffff'>\\s*<tr>\\s*<td align=\"left\" valign=\"top\" width=\"20%\"> <span class=\"tl\">Sídlo: <\\/span><\\/td>\\s*<td align=\"left\" width=\"80%\"><table width=\"100%\" border=\"0\">\\s*<tr>\\s*<td width=\"67%\"> <span class='ra'>(?<street>[^<]*)<\\/span> <span class='ra'>(?<number>[^<]*)<\\/span><br> <span class='ra'>(?<city>[^<]*)<\\/span> <span class='ra'>(?<zip>[^<]*)<\\/span><br><\\/td>\\s*<td width=\"33%\" valign='top'> <span class='ra'>\\(od: \\d{2}\\.\\d{2}\\.\\d{4}\\)<\\/span><\\/td>\\s*<\\/tr>\\s*<\\/table><\\/td>\\s*<\\/tr>\\s*<\\/table>\\s*<table width=\"100%\" border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"0\" bgcolor='#ffffff'>\\s*<tr>\\s*<td align=\"left\" valign=\"top\" width=\"20%\"> <span class=\"tl\">IČO: <\\/span><\\/td>\\s*<td align=\"left\" width=\"80%\"><table width=\"100%\" border=\"0\">\\s*<tr>\\s*<td width=\"67%\"> <span class='ra'>(?<id>[^<]*)<\\/span><br><\\/td>/i", $data, $tmp);
return ['name' => Strings::trim(html_entity_decode(@$tmp['name'][0])), 'address' => ['street' => Strings::trim(@$tmp['street'][0]), 'number' => Strings::trim(@$tmp['number'][0]), 'city' => Strings::trim(@$tmp['city'][0]), 'zip' => Strings::trim(str_replace(' ', '', @$tmp['zip'][0]))], 'id' => Strings::trim(str_replace(' ', '', @$tmp['id'][0]))];
}
示例4: getMapper
/**
* Get mapper
* @param string $contentType in format mimeType[; charset=utf8]
* @return IMapper
*
* @throws InvalidStateException
*/
public function getMapper($contentType)
{
$contentType = explode(';', $contentType);
$contentType = Strings::trim($contentType[0]);
if (!isset($this->services[$contentType])) {
throw new InvalidStateException('There is no mapper for Content-Type: ' . $contentType);
}
return $this->services[$contentType];
}
示例5: getControl
public function getControl()
{
$el = parent::getControl();
if ($this->emptyValue !== '') {
$el->attrs['data-nette-empty-value'] = Strings::trim($this->translate($this->emptyValue));
}
if (isset($el->placeholder)) {
$el->placeholder = $this->translate($el->placeholder);
}
return $el;
}
示例6: sanitize
private static function sanitize($type, $value)
{
if ($type === Form::DATA_TEXT) {
return is_scalar($value) ? Strings::normalizeNewLines($value) : NULL;
} elseif ($type === Form::DATA_LINE) {
return is_scalar($value) ? Strings::trim(strtr($value, "\r\n", ' ')) : NULL;
} elseif ($type === Form::DATA_FILE) {
return $value instanceof Nette\Http\FileUpload ? $value : NULL;
} else {
throw new Nette\InvalidArgumentException('Unknown data type');
}
}
示例7: extractTags
public function extractTags($input)
{
$matches = Strings::match($input, '/^\\s*(?<tag_list>\\[\\s*[\\pL\\d._-]+\\s*\\](?:\\s*(?&tag_list))?)/u');
if ($matches) {
$tags = Strings::trim($matches['tag_list'], '[] ');
$tags = Strings::split($tags, '/\\]\\s*\\[/');
$tags = array(array_map('Nette\\Utils\\Strings::webalize', $tags), $tags);
} else {
$tags = array();
}
return $tags;
}
示例8: parseDateTimeStringFromRawValue
/**
* @param string $rawValue
* @return string[]
* @throws DateTimeParseException
*/
private function parseDateTimeStringFromRawValue($rawValue)
{
$parts = explode($this->delimiter, Strings::trim($rawValue));
$partsSize = count($parts);
if ($partsSize % 2 !== 0) {
throw new DateTimeParseException('Error in parsing interval. Mishmash in delimiters.');
}
$sliceSize = count($parts) / 2;
$leftValue = implode($this->delimiter, array_slice($parts, 0, $sliceSize));
$rightValue = implode($this->delimiter, array_slice($parts, $sliceSize, $partsSize));
return [$leftValue, $rightValue];
}
示例9: renderResults
public function renderResults($query, $page = NULL, $filter = NULL)
{
if (!Strings::trim($query)) {
$this->redirect('Homepage:default');
}
$this['searchResultsForm-form-query']->setDefaultValue($query);
$this->template->query = $query;
$this->template->filter = $filter;
list($limit, $offset) = $this->getLinearLimitOffset($page ?: 1);
$this->template->search = $results = $this->search->query($query, $limit, $offset, $filter);
$this->payload->results = $results->count();
$this->redrawControl('results');
}
示例10: parseTimes
/**
* Parses allowed time ranges for cron task. If annotation is invalid
* throws exception.
*
* @param string $annotation
* @return string[][]|null
* @throws \stekycz\Cronner\InvalidParameterException
*/
public static function parseTimes($annotation)
{
$times = NULL;
static::checkAnnotation($annotation);
$annotation = Strings::trim($annotation);
if (Strings::length($annotation)) {
if ($values = static::splitMultipleValues($annotation)) {
$times = array();
foreach ($values as $time) {
$times = array_merge($times, static::parseOneTime($time));
}
usort($times, function ($a, $b) {
return $a < $b ? -1 : ($a > $b ? 1 : 0);
});
}
}
return $times ?: NULL;
}
示例11: parseQuery
/**
* Parse search query.
*
* @param string
* @return array associative array with keys 'query' and 'tags'
*/
public function parseQuery($input)
{
// normalize input
$input = Strings::lower(Strings::trim($input));
$input = Strings::replace($input, '/\\s+/', ' ');
// extract tags
$matches = Strings::matchAll($input, '/(?<=^|\\s)tag:\\s*(?<tag_list>[\\pL\\d_-]+(?:\\s*,\\s*(?&tag_list))?)/u');
$tags = array();
$query = $input;
foreach ($matches as $m) {
$tmp = Strings::split($m['tag_list'], '/\\s*,\\s*/');
$tmp = array_map('Nette\\Utils\\Strings::webalize', $tmp);
$tmp = array_unique($tmp);
$tags = array_merge($tags, $tmp);
$query = str_replace($m[0], '', $query);
}
$query = Strings::trim($query) ?: null;
return array('query' => $query, 'tags' => $tags);
}
示例12: handleEdit
public function handleEdit($pk, $value)
{
$value = Strings::trim($value);
if (!$value) {
$this->sendJson(['status' => 'error', 'message' => 'Název stavu nesmí být prázdný']);
}
$state = $this->states->findOneBy(['label' => $value]);
if ($state) {
$this->sendJson(['status' => 'error', 'message' => 'Již existuje stav s popiskem ' . $value]);
}
/** @var State $state */
$state = $this->states->find($pk);
if (!$state) {
$this->sendJson(['status' => 'error', 'message' => 'Nebyl nalezen upravovaný stav']);
}
$state->label = $value;
$this->states->save($state);
$this->sendJson(['status' => 'success', 'pk' => $pk, 'new label' => $value]);
}
示例13: to
/**
* @param string $name
* @param NULL|string $gender
* @return bool|string
*/
public function to($name, $gender = NULL)
{
$name = Strings::fixEncoding($name);
$name = Strings::trim($name);
$name = Strings::lower($name);
$url = self::API_URL . '?name=' . urlencode($name);
if ($this->type !== NULL) {
$url .= '&type=' . urlencode($this->type);
}
if ($gender !== NULL) {
$url .= '&gender=' . urlencode($gender);
}
return $this->cache->load($url, function ($dependencies) use($url) {
$data = $this->simpleCurl->get($url);
$json = self::parseJson($data);
$result = $json->success ? $json->results[0] : FALSE;
$this->cache->save($url, $result, $dependencies);
return $result;
});
}
示例14: 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;
}
}
示例15: getCommandOptions
/**
* Returns options part of command
*
* @param mixed $width
* @param mixed $height
* @param null|int $quality
* @return string
*/
private function getCommandOptions($width, $height, $quality)
{
$options = [];
if (isset($width) && (int) $width === 0) {
$width = $this->image->getWidth() . '!';
}
if (isset($height) && (int) $height === 0) {
$height = $this->image->getHeight() . '!';
}
if (!isset($height)) {
$options['resize'] = '"' . $width . '"';
} elseif (!isset($width)) {
$options['resize'] = '"x' . $height . '"';
} else {
$options['resize'] = '"' . Strings::trim($width, '!') . 'x' . Strings::trim($height, '!') . '^"';
}
if (isset($width) && isset($height)) {
$options['gravity'] = 'center';
$options['crop'] = '"' . $width . 'x' . $height . '+0+0"';
}
if (isset($quality) && $quality !== 0) {
$options['quality'] = $quality;
}
$command = [];
foreach ($options as $opt => $value) {
$command[] = '-' . $opt . ' ' . $value;
}
return implode(' ', $command);
}