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


PHP StringUtil::length方法代码示例

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


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

示例1: execute

 /**
  * @see TemplatePluginModifier::execute()
  */
 public function execute($tagArgs, Template $tplObj)
 {
     // default values
     $length = 80;
     $etc = '...';
     $breakWords = false;
     // get values
     $string = $tagArgs[0];
     if (isset($tagArgs[1])) {
         $length = intval($tagArgs[1]);
     }
     if (isset($tagArgs[2])) {
         $etc = $tagArgs[2];
     }
     if (isset($tagArgs[3])) {
         $breakWords = $tagArgs[3];
     }
     // execute plugin
     if ($length == 0) {
         return '';
     }
     if (StringUtil::length($string) > $length) {
         $length -= StringUtil::length($etc);
         if (!$breakWords) {
             $string = preg_replace('/\\s+?(\\S+)?$/', '', StringUtil::substring($string, 0, $length + 1));
         }
         return StringUtil::substring($string, 0, $length) . $etc;
     } else {
         return $string;
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:34,代码来源:TemplatePluginModifierTruncate.class.php

示例2: checkCondition

 /**
  * Checks the condition.
  *
  * @param	PMRuleCondition		$condition
  * @param	string			$string
  * @return	boolean
  */
 protected function checkCondition(PMRuleCondition $condition, $string)
 {
     $value = StringUtil::toLowerCase($condition->ruleConditionValue);
     $string = StringUtil::toLowerCase($string);
     switch ($condition->ruleCondition) {
         case 'contains':
             if (StringUtil::indexOf($string, $value) !== false) {
                 return true;
             }
             break;
         case 'dontContains':
             if (StringUtil::indexOf($string, $value) === false) {
                 return true;
             }
             break;
         case 'beginsWith':
             if (StringUtil::indexOf($string, $value) === 0) {
                 return true;
             }
             break;
         case 'endsWith':
             if (StringUtil::substring($string, -1 * StringUtil::length($value)) == $value) {
                 return true;
             }
             break;
         case 'isEqualTo':
             if ($value == $string) {
                 return true;
             }
             break;
     }
     return false;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:40,代码来源:SenderPMRuleConditionType.class.php

示例3: validate

 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if (empty($this->message)) {
         throw new UserInputException('message');
     }
     if (StringUtil::length($this->message) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) {
         throw new UserInputException('message', 'tooLong');
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:13,代码来源:ContestJurytalkAddForm.class.php

示例4: getMessagePreview

 /**
  * Returns an excerpt of this private message.
  * 
  * @return	string
  */
 public function getMessagePreview()
 {
     AttachmentBBCode::setMessageID($this->pmID);
     $parser = MessageParser::getInstance();
     $parser->setOutputType('text/plain');
     $message = $parser->parse($this->message, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes, false);
     if (StringUtil::length($message) > 500) {
         $message = StringUtil::substring($message, 0, 497) . '...';
     }
     return $message;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:16,代码来源:ViewablePM.class.php

示例5: validate

 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     if (empty($this->comment)) {
         throw new UserInputException('comment');
     }
     if (StringUtil::length($this->comment) > WCF::getUser()->getPermission('user.contest.maxSolutionLength')) {
         throw new UserInputException('comment', 'tooLong');
     }
     // username
     $this->validateUsername();
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:15,代码来源:ContestCommentAddForm.class.php

示例6: getExcerpt

 /**
  * Returns an excerpt of the message.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     $enableSmilies = 1;
     $enableHtml = 0;
     $enableBBCodes = 1;
     MessageParser::getInstance()->setOutputType('text/plain');
     $message = MessageParser::getInstance()->parse($this->comment, $enableSmilies, $enableHtml, $enableBBCodes);
     // get abstract
     if (StringUtil::length($message) > 50) {
         $message = StringUtil::substring($message, 0, 47) . '...';
     }
     return $message;
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:18,代码来源:ViewableContestComment.class.php

示例7: getTitle

 /**
  * @see NotificationObject::getTitle()
  */
 public function getTitle()
 {
     $message = $this->getFormattedMessage('text/plain');
     $message = StringUtil::stripHTML($message);
     $message = StringUtil::trim($message);
     if (StringUtil::length($message) > 100) {
         $message = StringUtil::substring($message, 0, 97) . '...';
     }
     if (empty($message)) {
         $message = '#' . $this->entryID;
     }
     return $message;
 }
开发者ID:0xLeon,项目名称:com.leon.wbb.notification.post.delete,代码行数:16,代码来源:PostDeleteNotificationObject.class.php

示例8: isValidUsername

 /**
  * Returns true, if the given name is a valid username.
  * 
  * @param	string		$name		username
  * @return 	boolean
  */
 public static function isValidUsername($name)
 {
     // check illegal characters
     if (!preg_match('!^[^,\\n]+$!', $name)) {
         return false;
     }
     // check long words
     $words = preg_split('!\\s+!', $name, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($words as $word) {
         if (StringUtil::length($word) > 20) {
             return false;
         }
     }
     return true;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:21,代码来源:UserUtil.class.php

示例9: getExcerpt

 /**
  * Returns an excerpt of the message.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     // pre-format
     $message = StringUtil::trim(StringUtil::unifyNewlines($this->message));
     // find 1st paragraph
     $excerpt = preg_replace('/^(.*?)\\n\\n.*/s', '$1', $message);
     if (StringUtil::length($excerpt) != StringUtil::length($message)) {
         $this->data['hasMoreText'] = 1;
     }
     // format
     require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
     MessageParser::getInstance()->setOutputType('text/html');
     require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
     AttachmentBBCode::setMessageID($this->contestID);
     return MessageParser::getInstance()->parse($excerpt, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes);
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:21,代码来源:ViewableContest.class.php

示例10: getExcerpt

 /**
  * Returns an excerpt of the help item.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     // get text
     $description = WCF::getLanguage()->getDynamicVariable('wcf.help.item.' . $this->helpItem . '.description');
     // remove headlines
     $description = preg_replace('~<h4>.*?</h4>~', '', $description);
     // remove help images
     $description = preg_replace('~<p class="helpImage.*?</p>~s', '', $description);
     // strip html tags
     $description = strip_tags($description);
     // truncate text
     if (StringUtil::length($description) > 250) {
         $description = preg_replace('/\\s+?(\\S+)?$/', '', StringUtil::substring($description, 0, 251));
         $description = StringUtil::substring($description, 0, 250) . '...';
     }
     return $description;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:22,代码来源:HelpItem.class.php

示例11: validate

	/**
	 * @see Form::validate()
	 */
	public function validate() {
		parent::validate();
		
		if (empty($this->pageName))
			throw new UserInputException('pageName', 'empty');
		
		if (!preg_match('/^[a-z0-9_-]+$/i', $this->pageName))
			throw new UserInputException('pageName', 'invalid');
		
		if (StringUtil::length($this->pageName) > 20)
			throw new UserInputException('pageName', 'tooLong');
		
		if (empty($this->menuItem))
			throw new UserInputException('menuItem', 'empty');
		
		if (StringUtil::length($this->menuItem) > 20)
			throw new UserInputException('menuItem', 'tooLong');
	}
开发者ID:nachteule,项目名称:nachteule.wcf.customuserpages,代码行数:21,代码来源:UserCustomPageAddForm.class.php

示例12: autoload

 /**
  * autoload method for classname
  *
  * @param 	string		$className
  */
 public function autoload($className)
 {
     if (!isset($className)) {
         throw new SystemException('missing className');
     }
     $className = StringUtil::getClassName($className);
     $dir = StringUtil::toLowercase(StringUtil::substring($className, StringUtil::length('ViewableContest')));
     if (empty($dir)) {
         throw new SystemException('wrong dir: ' . $dir);
     }
     $file = WCF_DIR . 'lib/data/contest/' . $dir . '/' . $className . '.class.php';
     if (!is_file($file)) {
         throw new SystemException('wrong file: ' . $file);
     }
     require_once $file;
     if (!class_exists($className)) {
         throw new SystemException('class does not exist: ' . $className);
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:24,代码来源:ContestEventMix.class.php

示例13: __construct

 public function __construct($data, $boxname = "")
 {
     $this->threadLastPostsBoxData['templatename'] = "threadlastpostsbox";
     $this->getBoxStatus($data);
     $this->threadLastPostsBoxData['boxID'] = $data['boxID'];
     $cntPosts = 0;
     if (!defined('THREADLASTPOSTSBOX_THREADID')) {
         define('THREADLASTPOSTSBOX_THREADID', 0);
     }
     if (!defined('THREADLASTPOSTSBOX_LIMIT')) {
         define('THREADLASTPOSTSBOX_LIMIT', 10);
     }
     if (!defined('THREADLASTPOSTSBOX_TITLELENGTH')) {
         define('THREADLASTPOSTSBOX_TITLELENGTH', 28);
     }
     if (!defined('THREADLASTPOSTSBOX_SBCOLOR')) {
         define('THREADLASTPOSTSBOX_SBCOLOR', 2);
     }
     require_once WBB_DIR . 'lib/data/board/Board.class.php';
     $boardIDs = Board::getAccessibleBoards();
     if (!empty($boardIDs) && THREADLASTPOSTSBOX_THREADID) {
         $sql = "SELECT wp.postID, wp.threadID, wp.userID, wp.subject, wp.message, wp.time" . "\n  FROM wbb1_1_post wp" . "\n  JOIN wbb1_1_thread wt ON (wt.threadID = wp.threadID)" . "\n WHERE wp.threadID = " . THREADLASTPOSTSBOX_THREADID . "\n   AND wp.isDeleted = 0" . "\n   AND wp.isDisabled = 0" . "\n   AND wt.isDeleted = 0" . "\n   AND wt.isDisabled = 0" . "\n   AND wt.boardID IN (" . $boardIDs . ")" . "\n ORDER BY wp.postID DESC" . "\n  LIMIT 0, " . THREADLASTPOSTSBOX_LIMIT;
         $result = WBBCore::getDB()->sendQuery($sql);
         while ($row = WBBCore::getDB()->fetchArray($result)) {
             if (!empty($row['subject'])) {
                 $title = $row['subject'];
             } else {
                 $title = preg_replace('/\\[/', '<', $row['message']);
                 $title = preg_replace('/\\]/', '>', $title);
                 $title = strip_tags($title);
                 //StringUtil::stripHTML($title);
             }
             if (THREADLASTPOSTSBOX_TITLELENGTH != 0 && StringUtil::length($title) > THREADLASTPOSTSBOX_TITLELENGTH) {
                 $title = StringUtil::substring($title, 0, THREADLASTPOSTSBOX_TITLELENGTH - 3) . '...';
             }
             $row['title'] = StringUtil::encodeHTML($title);
             $this->threadLastPostsBoxData['box'][] = $row;
             $cntPosts++;
         }
     }
     WCF::getTPL()->assign(array('THREADLASTPOSTSBOX_SBCOLOR' => intval(THREADLASTPOSTSBOX_SBCOLOR), 'threadLastPostBoxCnt' => $cntPosts));
 }
开发者ID:Maggan22,项目名称:wbb3addons,代码行数:42,代码来源:ThreadLastPostsBox.class.php

示例14: validate

 /**
  * @see Form::validate()
  */
 public function validate()
 {
     ACPForm::validate();
     if (empty($this->masterPassword)) {
         throw new UserInputException('masterPassword');
     }
     // check password security
     if (StringUtil::length($this->masterPassword) < 8) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // digits
     if (!preg_match('![0-9]+!', $this->masterPassword)) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // latin characters (lower-case)
     if (!preg_match('![a-z]+!', $this->masterPassword)) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // latin characters (upper-case)
     if (!preg_match('![A-Z]+!', $this->masterPassword)) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // special characters
     if (!preg_match('![^A-Za-z0-9]+!', $this->masterPassword)) {
         throw new UserInputException('masterPassword', 'notSecure');
     }
     // search for identical admin passwords
     $sql = "SELECT\tpassword, salt\n\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\tWHERE\tuserID IN (\n\t\t\t\t\tSELECT\tuserID\n\t\t\t\t\tFROM\twcf" . WCF_N . "_user_to_groups\n\t\t\t\t\tWHERE\tgroupID = 4\n\t\t\t\t)";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (StringUtil::getDoubleSaltedHash($this->masterPassword, $row['salt']) == $row['password']) {
             throw new UserInputException('masterPassword', 'notSecure');
         }
     }
     // confirm master password
     if (empty($this->confirmMasterPassword)) {
         throw new UserInputException('confirmMasterPassword');
     }
     if ($this->confirmMasterPassword != $this->masterPassword) {
         throw new UserInputException('confirmMasterPassword', 'notEqual');
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:45,代码来源:MasterPasswordInitForm.class.php

示例15: isSecurePassword

 /**
  * Returns true, if the given password is secure.
  * 
  * @param	string		$password
  * @return 	boolean
  */
 public static function isSecurePassword($password)
 {
     if (REGISTER_ENABLE_PASSWORD_SECURITY_CHECK) {
         if (StringUtil::length($password) < REGISTER_PASSWORD_MIN_LENGTH) {
             return false;
         }
         if (REGISTER_PASSWORD_MUST_CONTAIN_DIGIT && !preg_match('![0-9]+!', $password)) {
             return false;
         }
         if (REGISTER_PASSWORD_MUST_CONTAIN_LOWER_CASE && !preg_match('![a-z]+!', $password)) {
             return false;
         }
         if (REGISTER_PASSWORD_MUST_CONTAIN_UPPER_CASE && !preg_match('![A-Z]+!', $password)) {
             return false;
         }
         if (REGISTER_PASSWORD_MUST_CONTAIN_SPECIAL_CHAR && !preg_match('![^A-Za-z0-9]+!', $password)) {
             return false;
         }
     }
     return true;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:27,代码来源:UserRegistrationUtil.class.php


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