当前位置: 首页>>代码示例>>PHP>>正文


PHP str类代码示例

本文整理汇总了PHP中str的典型用法代码示例。如果您正苦于以下问题:PHP str类的具体用法?PHP str怎么用?PHP str使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了str类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的str类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。