本文整理汇总了PHP中str类的典型用法代码示例。如果您正苦于以下问题:PHP str类的具体用法?PHP str怎么用?PHP str使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了str类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: bar
function bar(str $k)
{
$tmp = 54;
try {
$y = $k->__toString();
$tmp = 2;
} catch (Exception $x) {
var_dump($tmp);
}
var_dump($tmp);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:11,代码来源:dce_004.php
示例2: __destruct
public function __destruct()
{
flush();
if (!is_dir(ROOT . 'task')) {
return false;
}
if (AJAX) {
return false;
}
//ajax操作的时候不做计划任务
if (defined('CLOSETASK')) {
return false;
}
extract($this->info);
/** 分时计划任务 **/
$file = new file();
$db = new db();
$str = new str();
$time = time();
$today = $str->formatDate($time, 'Ymd');
for ($i_task = 1; $i_task <= 6; $i_task++) {
if ($time - intval(kc_config('task.update' . $i_task)) > 3600 * $i_task) {
$tasks = $file->getDir('task/' . $i_task . '/', 'php');
if (!empty($tasks)) {
foreach ($tasks as $k => $v) {
require ROOT . $k;
}
}
unset($tasks);
$db->update('%s_config', array('value' => $time), "class='task' and name='update{$i_task}'");
}
}
//开始执行每日计划任务
if (kc_config('task.day') != $today) {
$tasks = $file->getDir('task/day/', 'php');
if (!empty($tasks)) {
foreach ($tasks as $k => $v) {
require ROOT . $k;
}
}
unset($tasks);
$db->update('%s_config', array('value' => $today), "class='task' and name='day'");
}
//刷新即可执行
$tasks = $file->getDir('task/0/', 'php');
if (!empty($tasks)) {
foreach ($tasks as $k => $v) {
require ROOT . $k;
}
}
}
开发者ID:kissthink,项目名称:ym_oauth,代码行数:51,代码来源:user.class.php
示例3: plural
/**
* Return the plural of the input string if quantity is larger than one.
*
* NOTE: This function will not handle any special cases.
*
* @see http://www.oxforddictionaries.com/words/plurals-of-nouns
*
* @param string $singular Singular noun
* @param integer $quantity Quantity
* @param string $plural Plural form
*
* @return string
*/
public static function plural($singular, $quantity = 2, $plural = null)
{
if ($quantity <= 1 || empty($singular)) {
return $singular;
}
if (!is_null($plural)) {
return $plural;
}
$last = str::lower($singular[str::length($singular) - 1]);
$lastTwo = str::lower(substr($singular, 0, -2));
if ('y' === $last) {
return substr($singular, 0, -1) . 'ies';
} else {
if ('f' === $last || 'fe' === $lastTwo) {
return $singular . 'ves';
} else {
if (in_array($last, array('s', 'x', 'z'))) {
return substr($singular, 0, -1) . 'es';
} else {
if (in_array($lastTwo, array('ch', 'sh'))) {
return substr($singular, 0, -2) . 'es';
} else {
return $singular . 's';
}
}
}
}
}
开发者ID:buditanrim,项目名称:kirby-comments,代码行数:41,代码来源:str.php
示例4: update
public function update($data = array())
{
if (!panel()->user()->isAdmin() and !$this->isCurrent()) {
throw new Exception(l('users.form.error.update.rights'));
}
// users which are not an admin cannot change their role
if (!panel()->user()->isAdmin()) {
unset($data['role']);
}
if (str::length(a::get($data, 'password')) > 0) {
if (a::get($data, 'password') !== a::get($data, 'passwordconfirmation')) {
throw new Exception(l('users.form.error.password.confirm'));
}
} else {
unset($data['password']);
}
unset($data['passwordconfirmation']);
if ($this->isLastAdmin() and a::get($data, 'role') !== 'admin') {
// check the number of left admins to not convert the last one
throw new Exception(l('user.error.lastadmin'));
}
parent::update($data);
// flush the cache in case if the user data is
// used somewhere on the site (i.e. for profiles)
kirby()->cache()->flush();
kirby()->trigger('panel.user.update', $this);
return $this;
}
开发者ID:robinandersen,项目名称:robin,代码行数:28,代码来源:user.php
示例5: login
public function login($welcome = null)
{
if ($user = panel()->site()->user()) {
go(panel()->urls()->index());
}
$message = l('login.error');
$error = false;
$form = panel()->form('login');
$form->cancel = false;
$form->save = l('login.button');
$form->centered = true;
if (r::is('post') and get('_csfr') and csfr(get('_csfr'))) {
$data = $form->serialize();
$user = site()->user(str::lower($data['username']));
if (!$user) {
$error = true;
} else {
if (!$user->hasPanelAccess()) {
$error = true;
} else {
if (!$user->login(get('password'))) {
$error = true;
} else {
go(panel()->urls()->index());
}
}
}
}
if ($username = s::get('username')) {
$form->fields->username->value = html($username, false);
}
return layout('login', array('meta' => new Snippet('meta'), 'welcome' => $welcome ? l('login.welcome') : '', 'form' => $form, 'error' => $error ? $message : false));
}
开发者ID:LucasFyl,项目名称:korakia,代码行数:33,代码来源:auth.php
示例6: truncateString
function truncateString($text, $length)
{
ob_start();
$short = \str::short($text, $length);
ob_end_clean();
return $short;
}
开发者ID:aizlewood,项目名称:2016,代码行数:7,代码来源:comments.php
示例7: crawl
function crawl()
{
$path = url::strip_query($this->raw);
$path = (array) str::split($path, '/');
if (a::first($path) == 'index.php') {
array_shift($path);
}
// parse params
foreach ($path as $p) {
if (str::contains($p, ':')) {
$parts = explode(':', $p);
if (count($parts) < 2) {
continue;
}
$this->params->{$parts}[0] = $parts[1];
} else {
$this->path->_[] = $p;
}
}
// get the extension from the last part of the path
$this->extension = f::extension($this->path->last());
if ($this->extension != false) {
// remove the last part of the path
$last = array_pop($this->path->_);
$this->path->_[] = f::name($last);
}
return $this->path;
}
开发者ID:narrenfrei,项目名称:kirbycms,代码行数:28,代码来源:uri.php
示例8: get
/**
* Gets a value from the _SERVER array
*
* <code>
*
* server::get('document_root');
* // sample output: /var/www/kirby
*
* server::get();
* // returns the whole server array
*
* </code>
*
* @param mixed $key The key to look for. Pass false or null to return the entire server array.
* @param mixed $default Optional default value, which should be returned if no element has been found
* @return mixed
*/
public static function get($key = false, $default = null)
{
if (empty($key)) {
return $_SERVER;
}
return a::get($_SERVER, str::upper($key), $default);
}
开发者ID:chrishiam,项目名称:LVSL,代码行数:24,代码来源:server.php
示例9: __construct
public function __construct($config = array())
{
// Set the config
$this->config = $config;
// Set a filename, if we don't have one
if (str::e($this->config['filename'])) {
$this->config['filename'] = date("Y-m-d_g-ia");
}
// Build driver class
$driver = "Export_Driver_" . trim(strtoupper($config['driver']));
// Load the driver
if (!Eight::auto_load($driver)) {
throw new Export_Exception('export.driver_not_supported', $config['driver']);
}
// Initialize the driver
$this->driver = new $driver($this->config);
// Validate the driver
if (!$this->driver instanceof Export_Driver) {
throw new Export_Exception('export.driver_not_supported', 'Export drivers must use the Export_Driver interface.');
}
// Set the columns
if (!arr::e($this->config['columns'])) {
$this->driver->set_columns($this->config['columns']);
}
}
开发者ID:enormego,项目名称:EightPHP,代码行数:25,代码来源:export.php
示例10: register
/**
* Adds a new route
*
* @param object $route
* @return object
*/
public function register($pattern, $params = array(), $optional = array())
{
if (is_array($pattern)) {
foreach ($pattern as $v) {
$this->register($v['pattern'], $v);
}
return $this;
}
$defaults = array('pattern' => $pattern, 'https' => false, 'ajax' => false, 'filter' => null, 'method' => 'GET', 'arguments' => array());
$route = new Obj(array_merge($defaults, $params, $optional));
// convert single methods or methods separated by | to arrays
if (is_string($route->method)) {
if (strpos($route->method, '|') !== false) {
$route->method = str::split($route->method, '|');
} else {
if ($route->method == 'ALL') {
$route->method = array_keys($this->routes);
} else {
$route->method = array($route->method);
}
}
}
foreach ($route->method as $method) {
$this->routes[strtoupper($method)][$route->pattern] = $route;
}
return $route;
}
开发者ID:chrishiam,项目名称:LVSL,代码行数:33,代码来源:router.php
示例11: update
public function update($username)
{
$user = $this->user($username);
if (!$user) {
return response::error(l('users.edit.error.missing'));
} else {
if (!site()->user()->isAdmin() and !$user->isCurrent()) {
return response::error('You are not allowed to edit this user');
}
$form = $this->form($user);
$data = $form->toArray();
if (str::length($data['password']) > 0) {
if ($data['password'] !== $data['passwordconfirmation']) {
return response::error(l('users.form.error.password.confirm'));
}
} else {
unset($data['password']);
}
unset($data['passwordconfirmation']);
if ($user->update($data)) {
return response::success('success');
} else {
return response::error(l('users.form.error.update'));
}
}
}
开发者ID:muten84,项目名称:luigibifulco.it,代码行数:26,代码来源:users.php
示例12: env
/**
* Gets the value of an environment variable. Supports boolean, empty and null.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function env($key, $default = null)
{
$value = getenv($key);
if ($value === false) {
return $default;
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
if (\str::startsWith($value, '"') && \str::endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
开发者ID:evendev,项目名称:apex-kirby,代码行数:32,代码来源:helpers.php
示例13: create_post
function create_post($page, $blueprint, $title, $data)
{
// Where we'll put the content.
$PATH = get_content_path($page);
$SLUG = str::slug($title);
$dir = $PATH . DS . $SLUG;
$dir_matches = glob($PATH . DS . "*" . $SLUG . "*");
// If the directory already exists don't override it,
// append a number to it, no matter its visibility.
// 1-directory
// directory_1
// 8-directory_2
if (count($dir_matches) > 0) {
$dir .= "_" . count($dir_matches);
$title .= "_" . count($dir_matches);
}
// Pass $title into the $data array for easiest manipulation.
$data["title"] = $title;
// Create the directory with read&write permissions.
mkdir($dir, 0777, true);
// Filename with (almost) multilingual support.
// Peraphs you'll want to create different files for each
// languages code.
$filename = $blueprint . ".fr.txt";
// Write the file.
$file = fopen($dir . DS . $filename, 'w');
if (flock($file, LOCK_EX)) {
fwrite($file, parse_data(get_blueprint($blueprint), $data));
flock($file, LOCK_EX);
}
fclose($file);
}
开发者ID:arnaudjuracek,项目名称:kirby-extensions,代码行数:32,代码来源:iftttbot.php
示例14: tagcloud
function tagcloud($parent, $options = array())
{
global $site;
// default values
$defaults = array('limit' => false, 'field' => 'tags', 'children' => 'visible', 'baseurl' => $parent->url(), 'param' => 'tag', 'sort' => 'name', 'sortdir' => 'asc');
// merge defaults and options
$options = array_merge($defaults, $options);
switch ($options['children']) {
case 'invisible':
$children = $parent->children()->invisible();
break;
case 'visible':
$children = $parent->children()->visible();
break;
default:
$children = $parent->children();
break;
}
$cloud = array();
foreach ($children as $p) {
$tags = str::split($p->{$options}['field']());
foreach ($tags as $t) {
if (isset($cloud[$t])) {
$cloud[$t]->results++;
} else {
$cloud[$t] = new obj(array('results' => 1, 'name' => $t, 'url' => $options['baseurl'] . '/' . $options['param'] . ':' . $t, 'isActive' => param($options['param']) == $t ? true : false));
}
}
}
$cloud = a::sort($cloud, $options['sort'], $options['sortdir']);
if ($options['limit']) {
$cloud = array_slice($cloud, 0, $options['limit']);
}
return $cloud;
}
开发者ID:niklausgerber,项目名称:themis,代码行数:35,代码来源:tagcloud.php
示例15: add
public function add($data)
{
$data['id'] = str::random(32);
$this->data[$data['id']] = $data;
$this->save();
return $data['id'];
}
开发者ID:nsteiner,项目名称:kdoc,代码行数:7,代码来源:store.php
示例16: parseFileAttributes
public function parseFileAttributes()
{
$source = $this->data[self::ARRAY_ATTR][self::PARA_IMG_SOURCE];
$source = is_object($source) ? $source : $this->imageExt->getPage()->file($source);
if ($source) {
$this->data[self::ARRAY_ATTR][self::PARA_IMG_SOURCE] = $source->filename();
$this->data[self::ARRAY_ATTR][self::PARA_IMG_SOURCE_MODIFIED] = $source->modified();
$this->data[self::ARRAY_ATTR][self::PARA_IMG_EXTENSION] = $source->extension();
$this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_FILENAME] = \str::template($this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_FILENAME], array('extension' => $source->extension(), 'name' => $source->name(), 'filename' => $source->filename(), 'safeName' => \f::safeName($source->name()), 'safeFilename' => \f::safeName($source->name()) . '.' . $this->data[self::ARRAY_ATTR][self::PARA_IMG_EXTENSION], 'width' => $this->data[self::ARRAY_ATTR][self::PARA_IMG_WIDTH], 'height' => $this->data[self::ARRAY_ATTR][self::PARA_IMG_HEIGHT], 'hash' => md5($source->root() . $this->settingsIdentifier())));
$this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_URL] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_URL] . '/' . $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_FILENAME];
$this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_ROOT] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_ROOT] . DS . $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_FILENAME];
if ($this->data[self::ARRAY_ATTR][self::PARA_GALLERY_ID] !== false && !empty($this->data[self::ARRAY_ATTR][self::PARA_GALLERY_ID])) {
$this->data[self::ARRAY_ATTR][self::PARA_LINK_URL] = $source->url();
}
if (is_string($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT]) && WebHelper::startsWith($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT], '{file-') && WebHelper::endsWith($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT], '}')) {
$field = substr($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT], 6, strlen($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT]) - 7);
$this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT] = $source->{$field}()->toString();
}
if (is_string($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE]) && WebHelper::startsWith($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE], '{file-') && WebHelper::endsWith($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE], '}')) {
$field = substr($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE], 6, strlen($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE]) - 7);
$this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE] = $source->{$field}()->toString();
}
if (is_string($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE]) && WebHelper::startsWith($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE], '{file-') && WebHelper::endsWith($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE], '}')) {
$field = substr($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE], 6, strlen($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE]) - 7);
$this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE] = $source->{$field}()->toString();
}
}
}
开发者ID:muten84,项目名称:luigibifulco.it,代码行数:28,代码来源:kirbycms-extension-image-lib-block-image.php
示例17: fields
public function fields($fields = null)
{
if (is_null($fields)) {
return $this->fields;
}
// get the site object
$site = panel()->site();
// check if untranslatable fields should be deactivated
$translated = $site->multilang() && !$site->language()->default();
foreach ($fields as $name => $field) {
$name = str_replace('-', '_', str::lower($name));
$field['name'] = $name;
$field['default'] = a::get($field, 'default', null);
$field['value'] = a::get($this->values(), $name, $field['default']);
// Pass through parent field name (structureField)
$field['parentField'] = $this->parentField;
// Check for untranslatable fields
if ($translated and isset($field['translate']) and $field['translate'] === false) {
$field['readonly'] = true;
$field['disabled'] = true;
}
$this->fields->append($name, static::field($field['type'], $field));
}
return $this;
}
开发者ID:nsteiner,项目名称:kdoc,代码行数:25,代码来源:form.php
示例18: create
public function create($uid, $template, $content = array())
{
if (empty($template)) {
throw new Exception(l('pages.add.error.template'));
}
$uid = empty($uid) ? str::random(32) : $uid;
$blueprint = new Blueprint($template);
$data = array();
foreach ($blueprint->fields(null) as $key => $field) {
$data[$key] = $field->default();
}
$data = array_merge($data, $content);
// create the new page and convert it to a page model
$page = new Page($this->page, parent::create($uid, $template, $data)->dirname());
if (!$page) {
throw new Exception(l('pages.add.error.create'));
}
kirby()->trigger('panel.page.create', $page);
// subpage builder
foreach ((array) $page->blueprint()->pages()->build() as $build) {
$missing = a::missing($build, array('title', 'template', 'uid'));
if (!empty($missing)) {
continue;
}
$subpage = $page->children()->create($build['uid'], $build['template'], array('title' => $build['title']));
if (isset($build['num'])) {
$subpage->sort($build['num']);
}
}
return $page;
}
开发者ID:nsteiner,项目名称:kdoc,代码行数:31,代码来源:children.php
示例19: __construct
/**
* @param string $id
* @param PageAbstract $product
*/
public function __construct($id, PageAbstract $product, $quantity)
{
$variant = false;
// Break cart ID into uri, variant, and option (:: is used as a delimiter)
$id_array = explode('::', $id);
// Set variant and option
$variantName = $id_array[1];
$variants = $product->variants()->yaml();
foreach ($variants as $key => $array) {
if (str::slug($array['name']) === $variantName) {
$variant = $variants[$key];
}
}
$this->id = $id;
$this->sku = $variant['sku'];
$this->uri = $product->uri();
$this->name = $product->title()->value;
$this->variant = str::slug($variant['name']);
$this->option = $id_array[2];
$this->amount = $variant['price'];
$this->sale_amount = salePrice($variant);
$this->weight = $variant['weight'];
$this->quantity = $quantity;
$this->noshipping = $product->noshipping()->value;
$this->notax = $product->notax()->value;
}
开发者ID:aguynamedirvin,项目名称:F-C,代码行数:30,代码来源:CartItem.php
示例20: __construct
/**
* Constructor
*
* @param mixed $source
* @param array $params
*/
public function __construct($source, $params = array())
{
$this->source = $this->result = is_a($source, 'Media') ? $source : new Media($source);
$this->options = array_merge(static::$defaults, $this->params($params));
$this->destination = new Obj();
$this->destination->filename = str::template($this->options['filename'], array('extension' => $this->source->extension(), 'name' => $this->source->name(), 'filename' => $this->source->filename(), 'safeName' => f::safeName($this->source->name()), 'safeFilename' => f::safeName($this->source->name()) . '.' . $this->extension(), 'width' => $this->options['width'], 'height' => $this->options['height'], 'hash' => md5($this->source->root() . $this->settingsIdentifier())));
$this->destination->url = $this->options['url'] . '/' . $this->destination->filename;
$this->destination->root = $this->options['root'] . DS . $this->destination->filename;
// don't create the thumbnail if it's not necessary
if ($this->isObsolete()) {
return;
}
// don't create the thumbnail if it exists
if (!$this->isThere()) {
// check for a valid image
if (!$this->source->exists() or $this->source->type() != 'image') {
throw new Error('The given image is invalid', static::ERROR_INVALID_IMAGE);
}
// check for a valid driver
if (!array_key_exists($this->options['driver'], static::$drivers)) {
throw new Error('Invalid thumbnail driver', static::ERROR_INVALID_DRIVER);
}
// create the thumbnail
$this->create();
// check if creating the thumbnail failed
if (!file_exists($this->destination->root)) {
return;
}
}
// create the result object
$this->result = new Media($this->destination->root, $this->destination->url);
}
开发者ID:muten84,项目名称:luigibifulco.it,代码行数:38,代码来源:thumb.php
注:本文中的str类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论