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


PHP str::length方法代码示例

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


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

示例1: validate

 public function validate()
 {
     // check for a valid library object
     if (!is_a($this->library, 'Library')) {
         throw new Exception('The library object is invalid');
     }
     // check for all required fields
     foreach (static::$required as $field) {
         if (empty($this->data[$field])) {
             throw new Exception('Missing required field: ' . $field);
         }
     }
     // id validation
     if (!is_string($this->data['id']) or !v::alphanum($this->data['id']) or str::length($this->data['id']) !== 32) {
         throw new Exception('Invalid id');
     }
     // type validation
     if (!is_string($this->data['type']) or !v::between($this->data['type'], 2, 32)) {
         throw new Exception('Invalid type');
     }
     // status validation
     if (!in_array($this->data['status'], static::$statuses)) {
         throw new Exception('Invalid status: ' . $this->data['status']);
     }
     // check for invalid updated timestamp
     if (!is_int($this->data['updated']) or !v::between(date('Y', $this->data['updated']), 1980, 2500)) {
         throw new Exception('Invalid updated timestamp');
     }
     // check for invalid created timestamp
     if (!is_int($this->data['created']) or !v::between(date('Y', $this->data['created']), 1980, 2500) or $this->data['created'] > time()) {
         throw new Exception('Invalid created timestamp');
     }
 }
开发者ID:Zegnat,项目名称:library,代码行数:33,代码来源:item.php

示例2: 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

示例3: 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

示例4: 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

示例5: __construct

 /**
  * Constructor
  * 
  * @param array $data
  */
 public function __construct($data = array())
 {
     foreach ($data as $key => $val) {
         if (!is_string($key) || str::length($key) === 0) {
             continue;
         }
         $this->{$key} = $val;
     }
 }
开发者ID:getkirby,项目名称:toolkit,代码行数:14,代码来源:obj.php

示例6: counter

 public function counter()
 {
     if (!$this->minLength() && !$this->maxLength() || $this->readonly()) {
         return null;
     }
     $counter = new Brick('div');
     $counter->addClass('field-counter marginalia text');
     $length = str::length(trim($this->value()));
     if ($this->outsideRange($length)) {
         $counter->addClass('outside-range');
     }
     $counter->data('field', 'counter');
     $counter->html($length . ($this->maxLength() ? '/' . $this->maxLength() : ''));
     return $counter;
 }
开发者ID:nsteiner,项目名称:kdoc,代码行数:15,代码来源:text.php

示例7: run

 public function run()
 {
     if (empty($this->query) or str::length($this->query) <= 1) {
         return false;
     }
     $data = $this->data();
     foreach ($data['pages'] as $page) {
         if (str::contains($page['title'], $this->query) or str::contains($page['uri'], $this->query)) {
             $this->pages->append($page['uri'], $page);
         }
     }
     foreach ($data['users'] as $user) {
         if (str::contains($user['username'], $this->query) or str::contains($user['email'], $this->query)) {
             $this->users->append($user['username'], $user);
         }
     }
     $this->pages = $this->pages->limit(5);
     $this->users = $this->users->limit(5);
 }
开发者ID:irenehilber,项目名称:kirby-base,代码行数:19,代码来源:search.php

示例8: update

 public function update($data = array())
 {
     if (!panel()->user()->isAdmin() and !$this->isCurrent()) {
         throw new Exception(l('users.form.error.update.rights'));
     }
     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);
     kirby()->trigger('panel.user.update', $this);
     return $this;
 }
开发者ID:biggtfish,项目名称:Clean-Blog-Kirby-Theme,代码行数:21,代码来源:user.php

示例9: update

 public function update($username)
 {
     $user = $this->user($username);
     if (!$user) {
         return response::error(l('users.edit.error.missing'));
     } else {
         $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:kompuser,项目名称:panel,代码行数:23,代码来源:users.php

示例10: send

 public function send()
 {
     if (c::get('email.disabled')) {
         return array('status' => 'error', 'msg' => l::get('email.disabled', 'Email has been disabled'));
     }
     if (!v::email($this->extractAddress($this->options['from']))) {
         return array('status' => 'error', 'msg' => l::get('email.error.invalid.sender', 'Invalid sender'));
     }
     if (!v::email($this->extractAddress($this->options['to']))) {
         return array('status' => 'error', 'msg' => l::get('email.error.invalid.recipient', 'Invalid recipient'));
     }
     if (!v::email($this->extractAddress($this->options['replyto']))) {
         return array('status' => 'error', 'msg' => l::get('email.error.invalid.replyto', 'Invalid Reply-To Address'));
     }
     if (str::length($this->options['subject']) == 0) {
         return array('status' => 'error', 'msg' => l::get('email.error.invalid.subject', 'The subject is missing'));
     }
     $method = 'sendWith' . str::ucfirst($this->options['use']);
     if (!method_exists(__CLASS__, $method)) {
         return array('status' => 'error', 'msg' => l::get('email.error.invalid.mailer', 'This email service is not supported'));
     }
     return $this->{$method}();
 }
开发者ID:scheibome,项目名称:kirbycms-extensions,代码行数:23,代码来源:email.php

示例11: function

 * Shortens the field value by the given length
 * @param Field $field The calling Kirby Field instance
 * @param integer $length The desired string length
 * @param string $rep The attached ellipsis character if the string is longer
 * @return string
 */
field::$methods['short'] = function ($field, $length, $rep = '…') {
    return str::short($field->value, $length, $rep);
};
/**
 * Returns the string length of the field value
 * @param Field $field The calling Kirby Field instance
 * @return integer
 */
field::$methods['length'] = function ($field) {
    return str::length($field->value);
};
/**
 * Returns the word count for the field value
 * @param Field $field The calling Kirby Field instance
 * @return integer
 */
field::$methods['words'] = function ($field) {
    return str_word_count(strip_tags($field->value));
};
/**
 * Splits the field value by the given separator
 * @param Field $field The calling Kirby Field instance
 * @param string $separator The string to split the field value by
 * @return array
 */
开发者ID:kristianhalte,项目名称:super_organic,代码行数:31,代码来源:methods.php

示例12: testLength

 public function testLength()
 {
     $this->assertEquals(20, str::length($this->sample));
 }
开发者ID:aoimedia,项目名称:kosmonautensofa,代码行数:4,代码来源:StrTest.php

示例13: editFile

 static function editFile()
 {
     global $panel, $page;
     $filename = get('filename');
     $newname = str::urlify(get('newname'));
     $file = $page->files()->find($filename);
     if (!$file) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.notfound'));
     }
     if (str::length($newname) < 1) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.filename'));
     }
     $newfilename = $newname . '.' . $file->extension();
     if ($newfilename != $file->filename()) {
         $newroot = dirname($file->root()) . '/' . $newfilename;
         if (file_exists($newroot)) {
             return array('status' => 'error', 'msg' => l::get('files.edit.errors.exists'));
         }
         if (!f::move($file->root(), $newroot)) {
             return array('status' => 'error', 'msg' => l::get('files.edit.errors.permissions'));
         }
         // delete the old meta file
         $oldmeta = dirname($file->root()) . '/' . $file->filename() . '.txt';
         f::remove($oldmeta);
     }
     $destination = dirname($file->root()) . '/' . $newfilename . '.txt';
     $updateInfo = self::updateFileinfo($file, $destination);
     if (error($updateInfo)) {
         return $updateInfo;
     }
     self::killCache();
     return array('status' => 'success', 'msg' => l::get('files.edit.success'));
 }
开发者ID:04x10,项目名称:04x10.com,代码行数:33,代码来源:data.php

示例14: license

 public function license()
 {
     $key = c::get('license');
     $type = 'trial';
     /**
      * Hey stranger, 
      * 
      * So this is the mysterious place where the panel checks for 
      * valid licenses. As you can see, this is not reporting
      * back to any server and the license keys are rather simple to 
      * hack. If you really feel like removing the warning in the panel
      * or tricking Kirby into believing you bought a valid license even 
      * if you didn't, go for it! But remember that literally thousands of 
      * hours of work have gone into Kirby in order to make your 
      * life as a developer, designer, publisher, etc. easier. If this 
      * doesn't mean anything to you, you are probably a lost case anyway. 
      * 
      * Have a great day! 
      * 
      * Bastian
      */
     if (str::startsWith($key, 'K2-PRO') and str::length($key) == 39) {
         $type = 'Kirby 2 Professional';
     } else {
         if (str::startsWith($key, 'K2-PERSONAL') and str::length($key) == 44) {
             $type = 'Kirby 2 Personal';
         } else {
             if (str::startsWith($key, 'MD-') and str::length($key) == 35) {
                 $type = 'Kirby 1';
             } else {
                 if (str::startsWith($key, 'BETA') and str::length($key) == 9) {
                     $type = 'Kirby 1';
                 } else {
                     if (str::length($key) == 32) {
                         $type = 'Kirby 1';
                     } else {
                         $key = null;
                     }
                 }
             }
         }
     }
     $localhosts = array('::1', '127.0.01', '0.0.0.0');
     return new Obj(array('key' => $key, 'local' => in_array(server::get('SERVER_ADDR'), $localhosts) or server::get('SERVER_NAME') == 'localhost', 'type' => $type));
 }
开发者ID:v1m0,项目名称:kirby-f6,代码行数:45,代码来源:panel.php

示例15: 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;
 }
开发者ID:buditanrim,项目名称:kirby-comments,代码行数:27,代码来源:config.php


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