本文整理汇总了PHP中str::substr方法的典型用法代码示例。如果您正苦于以下问题:PHP str::substr方法的具体用法?PHP str::substr怎么用?PHP str::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::substr方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSubstr
public function testSubstr()
{
$this->assertEquals('Super', str::substr($this->sample, 0, 5));
$this->assertEquals(' Äwes', str::substr($this->sample, 5, 5));
$this->assertEquals(' Äwesøme String', str::substr($this->sample, 5));
$this->assertEquals('tring', str::substr($this->sample, -5));
}
示例2: n
function n($page)
{
if ($page->isInvisible()) {
return '—';
} else {
if ($page->parent() and $blueprint = blueprint::find($page->parent())) {
switch ($blueprint->pages()->num()->mode()) {
case 'zero':
return str::substr($page->title(), 0, 1);
break;
case 'date':
return date('Y/m/d', strtotime($page->num()));
break;
default:
return intval($page->num());
break;
}
} else {
return intval($page->num());
}
}
}
示例3: Brick
if ($lazyload == true) {
// Only init griddiv when $gridcellclass or one or more width is set
if ($gridcellclass != '' || count($widths) > 0) {
$griddiv = new Brick('div');
}
$lazydiv = new Brick('div');
$lazydiv->addClass('FigureImage-lazy');
}
// set widths of all images
$width = $widths[$i];
// If there is one or more width set, use width variable(s)
if (count($widths) > 0) {
// the first part (the 1 of 3)
$classgridpart = str::substr($width, 0, 1);
// the total (the 3)
$classgridtot = str::substr($width, 3, 1);
// Add extra griddiv for lazyload
if ($lazyload == true) {
// Set the class for the image
$class = 'FigureImage-item';
// Set the class on the grid div
if (isset($griddiv)) {
$griddiv->addClass($gridcellclass . 'u-size' . $width . '--' . $break);
}
} else {
$class = 'FigureImage-item ' . $gridcellclass . 'u-size' . $width . '--' . $break;
}
} else {
// Add extra griddiv for lazyload
if ($lazyload == true) {
// Set the class for the image
示例4: ucfirst
/**
* An UTF-8 safe version of ucfirst()
*
* @param string $string
* @return string
*/
static function ucfirst($str)
{
return str::upper(str::substr($str, 0, 1)) . str::substr($str, 1);
}
示例5: page
public function page($uri)
{
if (str::startsWith($uri, '../')) {
if ($currentPage = $this->field->page) {
$path = $uri;
while (str::startsWith($path, '../')) {
if ($parent = $currentPage->parent()) {
$currentPage = $parent;
} else {
$currentPage = site();
}
$path = str::substr($path, 3);
}
if (!empty($path)) {
$currentPage = $currentPage->find($path);
}
$page = $currentPage;
} else {
$page = null;
}
} else {
if ($uri == '/') {
$page = site();
} else {
$page = page($uri);
}
}
return $page;
}
示例6: __construct
public function __construct($field)
{
$this->field = $field;
if (is_array($field->options)) {
$this->options = $field->options;
} else {
if (v::url($field->options)) {
$response = remote::get($field->options);
$options = @json_decode($response->content(), true);
if (is_array($options)) {
$this->options = $options;
} else {
$this->options = array();
}
} else {
if (!$field->page) {
$this->options = array();
} else {
if ($field->options == 'query') {
$defaults = array('page' => $field->page->id(), 'fetch' => 'children', 'value' => '{{uid}}', 'text' => '{{title}}', 'flip' => false, 'template' => false);
$query = array_merge($defaults, $field->query);
// dynamic page option
// ../
// ../../ etc.
if (str::startsWith($query['page'], '../')) {
$currentPage = $field->page;
$path = $query['page'];
while (str::startsWith($path, '../')) {
if ($parent = $currentPage->parent()) {
$currentPage = $parent;
} else {
break;
}
$path = str::substr($path, 3);
}
$page = $currentPage;
} else {
$page = page($query['page']);
}
$items = $this->items($page, $query['fetch']);
if ($query['template']) {
$items = $items->filter(function ($item) use($query) {
return in_array(str::lower($item->intendedTemplate()), array_map('str::lower', (array) $query['template']));
});
}
if ($query['flip']) {
$items = $items->flip();
}
foreach ($items as $item) {
$value = $this->tpl($query['value'], $item);
$text = $this->tpl($query['text'], $item);
$this->options[$value] = $text;
}
} else {
if ($items = $this->items($field->page, $field->options)) {
foreach ($items as $item) {
if (is_a($item, 'Page')) {
$this->options[$item->uid()] = (string) $item->title();
} else {
if (is_a($item, 'File')) {
$this->options[$item->filename()] = (string) $item->filename();
}
}
}
} else {
$this->options = array();
}
}
}
}
}
// sorting
if (!empty($this->field->sort)) {
switch (strtolower($this->field->sort)) {
case 'asc':
asort($this->options);
break;
case 'desc':
arsort($this->options);
break;
}
}
}
示例7: displayNum
public function displayNum()
{
if ($this->isInvisible()) {
return '—';
} else {
switch ($this->parent()->blueprint()->pages()->num()->mode()) {
case 'zero':
return str::substr($this->title(), 0, 1);
break;
case 'date':
return date('Y/m/d', strtotime($this->num()));
break;
default:
return intval($this->num());
break;
}
}
}
示例8: excerpt
/**
* Creates an excerpt without html and kirbytext
*
* @param mixed $text Variable object or string
* @param int $length The number of characters which should be included in the excerpt
* @param array $params an array of options for kirbytext: array('markdown' => true, 'smartypants' => true)
* @return string The shortened text
*/
function excerpt($text, $length = 140, $mode = 'chars')
{
if (strtolower($mode) == 'words') {
$text = str::excerpt(kirbytext($text), 0);
if (str_word_count($text, 0) > $length) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = str::substr($text, 0, $pos[$length]) . '...';
}
return $text;
} else {
return str::excerpt(kirbytext($text), $length);
}
}
示例9: gs
?>
']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'));</script>
<?php
}
// ----------------------------------------------------------
// Google Universal Analytics (optimized: http://j.mp/12dBWJm)
// ----------------------------------------------------------
if (c::get('analytics.tool') == 'ga-universal') {
?>
<script>(function(G,o,O,g,l){G.GoogleAnalyticsObject=O;G[O]||(G[O]=function(){(G[O].q=G[O].q||[]).push(arguments)});G[O].l=+new Date;g=o.createElement('script'),l=o.scripts[0];g.src='//www.google-analytics.com/analytics.js';l.parentNode.insertBefore(g,l)}(this,document,'ga'));ga('create','<?php
echo c::get("google.analytics.id", "TRACKING ID IS NOT SET");
?>
', '<?php
echo str::substr($site->url(), 7);
?>
');ga('send','pageview');</script>
<?php
}
// ----------------------------------------------------------
// GoSquared
// ----------------------------------------------------------
if (c::get('analytics') == 'gosquared') {
?>
<script>var GoSquared={};GoSquared.acct='<?php
echo c::get("gosquared.id", "TRACKING ID IS NOT SET");
?>
';(function(w){function gs(){w._gstc_lt=+new Date;var d=document,g=d.createElement('script');g.src='//d1l6p2sc9645hc.cloudfront.net/tracker.js';var s=d.getElementsByTagName('script')[0];s.parentNode.insertBefore(g,s);}w.addEventListener?w.addEventListener('load',gs,false):w.attachEvent('onload',gs);})(window);</script>
示例10: Error
throw new Error('Invalid identifier ' . $identifier);
}
});
/**
* Unquotes an identifier (table *or* column)
*
* @param $identifier string
* @return string
*/
sql::registerMethod('unquoteIdentifier', function ($sql, $identifier) {
// remove quotes around the identifier
if (in_array(str::substr($identifier, 0, 1), array('"', '`'))) {
$identifier = str::substr($identifier, 1);
}
if (in_array(str::substr($identifier, -1), array('"', '`'))) {
$identifier = str::substr($identifier, 0, -1);
}
// unescape duplicated quotes
return str_replace(array('""', '``'), array('"', '`'), $identifier);
});
/**
* Combines an identifier (table and column)
* MySQL version
*
* @param $table string
* @param $column string
* @param $values boolean Whether the identifier is going to be used for a values clause
* Only relevant for SQLite
* @return string
*/
sql::registerMethod('combineIdentifier', function ($sql, $table, $column, $values = false) {
示例11: displayNum
public function displayNum()
{
if ($this->isInvisible()) {
return '—';
} else {
$numberSettings = $this->parent()->blueprint()->pages()->num();
switch ($numberSettings->mode()) {
case 'zero':
if ($numberSettings->display()) {
// customer number display
return $this->{$numberSettings->display()}();
} else {
// alphabetic display numbers
return str::substr($this->title(), 0, 1);
}
break;
case 'date':
return $this->date($numberSettings->display(), $numberSettings->field());
break;
default:
if ($numberSettings->display()) {
// customer number display
return $this->{$numberSettings->display()}();
} else {
// regular number display
return intval($this->num());
}
break;
}
}
}
示例12: load
/**
* Load plugin options.
*
* @return array
*/
public function load()
{
// Retrieve all plugin options from the configuration starting with a
// prefix matching the plugin name
$prefix = $this->namespace . '.';
$keys = array_keys(c::$data);
$keys = array_filter($keys, function ($key) use($prefix) {
return str::startsWith($key, $prefix);
});
// Remove prefix and collect data
$options = array();
foreach ($keys as $key) {
$option = str::substr($key, str::length($prefix));
$options[$option] = c::$data[$key];
}
// Merge plugin settings with defaults
$defaults = $this->defaults();
if (is_array($defaults) && !empty($defaults)) {
$options = array_merge($defaults, $options);
}
return $options;
}