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


PHP StringUtil::substring方法代码示例

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


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

示例1: getFileExtension

	/**
	 * Returns the extension of the original file name.
	 * 
	 * @return	string
	 */
	public function getFileExtension() {
		if (($position = StringUtil::lastIndexOf($this->getFilename(), '.')) !== false) {
			return StringUtil::toLowerCase(StringUtil::substring($this->getFilename(), $position + 1));
		}
		
		return '';
	}
开发者ID:0xLeon,项目名称:WCF,代码行数:12,代码来源:UploadFile.class.php

示例2: parseEnableOptions

	/**
	 * Prepares JSON-encoded values for disabling or enabling dependent options.
	 * 
	 * @param	wcf\data\option\Option	$option
	 * @return	array
	 */
	protected function parseEnableOptions(Option $option) {
		$disableOptions = $enableOptions = '';
		
		if (!empty($option->enableOptions)) {
			$options = $option->parseMultipleEnableOptions();
			
			foreach ($options as $key => $optionData) {
				$tmp = explode(',', $optionData);
				
				foreach ($optionData as $item) {
					if ($item{0} == '!') {
						if (!empty($disableOptions)) $disableOptions .= ',';
						$disableOptions .= "{ value: '".$key."', option: '".StringUtil::substring($item, 1)."' }";
					}
					else {
						if (!empty($enableOptions)) $enableOptions .= ',';
						$enableOptions .= "{ value: '".$key."', option: '".$item."' }";
					}
				}
			}
		}
		
		return array(
			'disableOptions' => $disableOptions,
			'enableOptions' => $enableOptions
		);
	}
开发者ID:0xLeon,项目名称:WCF,代码行数:33,代码来源:SelectOptionType.class.php

示例3: execute

 /**
  * @see wcf\system\template\IModifierTemplatePlugin::execute()
  */
 public function execute($tagArgs, TemplateEngine $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:ZerGabriel,项目名称:WCF,代码行数:34,代码来源:TruncateModifierTemplatePlugin.class.php

示例4: insertPageNumber

 /**
  * Inserts the page number into the link.
  * 
  * @param 	string		$link
  * @param 	integer		$pageNo
  * @return	string		final link
  */
 protected static function insertPageNumber($link, $pageNo)
 {
     $startPos = StringUtil::indexOf($link, '%d');
     if ($startPos !== null) {
         $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2);
     }
     return $link;
 }
开发者ID:ZerGabriel,项目名称:WCF,代码行数:15,代码来源:PagesFunctionTemplatePlugin.class.php

示例5: __construct

 /**
  * Creates a new ActiveStyle object.
  * 
  * @param	Style	$object
  */
 public function __construct(Style $object)
 {
     parent::__construct($object);
     // calculate page logo path
     if (!empty($this->object->data['variables']['page.logo.image']) && !FileUtil::isURL($this->object->data['variables']['page.logo.image']) && StringUtil::substring($this->object->data['variables']['page.logo.image'], 0, 1) !== '/') {
         $this->object->data['variables']['page.logo.image'] = RELATIVE_WCF_DIR . $this->object->data['variables']['page.logo.image'];
     }
     // load icon cache
     $cacheName = 'icon-' . PACKAGE_ID . '-' . $this->styleID;
     CacheHandler::getInstance()->addResource($cacheName, WCF_DIR . 'cache/cache.' . $cacheName . '.php', 'wcf\\system\\cache\\builder\\IconCacheBuilder');
     $this->iconCache = CacheHandler::getInstance()->get($cacheName);
 }
开发者ID:ZerGabriel,项目名称:WCF,代码行数:17,代码来源:ActiveStyle.class.php

示例6: executeStart

 /**
  * @see wcf\system\template\ICompilerTemplatePlugin::executeStart()
  */
 public function executeStart($tagArgs, TemplateScriptingCompiler $compiler)
 {
     $compiler->pushTag('implode');
     if (!isset($tagArgs['from'])) {
         throw new SystemException($compiler->formatSyntaxError("missing 'from' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo()));
     }
     if (!isset($tagArgs['item'])) {
         throw new SystemException($compiler->formatSyntaxError("missing 'item' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo()));
     }
     $hash = StringUtil::getRandomID();
     $glue = isset($tagArgs['glue']) ? $tagArgs['glue'] : "', '";
     $this->tagStack[] = array('hash' => $hash, 'glue' => $glue);
     $phpCode = "<?php\n";
     $phpCode .= "\$_length" . $hash . " = count(" . $tagArgs['from'] . ");\n";
     $phpCode .= "\$_i" . $hash . " = 0;\n";
     $phpCode .= "foreach (" . $tagArgs['from'] . " as " . (isset($tagArgs['key']) ? (StringUtil::substring($tagArgs['key'], 0, 1) != '$' ? "\$this->v[" . $tagArgs['key'] . "]" : $tagArgs['key']) . " => " : '') . (StringUtil::substring($tagArgs['item'], 0, 1) != '$' ? "\$this->v[" . $tagArgs['item'] . "]" : $tagArgs['item']) . ") { ?>";
     return $phpCode;
 }
开发者ID:ZerGabriel,项目名称:WCF,代码行数:21,代码来源:ImplodeCompilerTemplatePlugin.class.php

示例7: getOptions

	/**
	 * Returns a list of options by object type id.
	 * 
	 * @param	integer		$objectTypeID
	 * @param	string		$categoryName
	 * @return	wcf\data\acl\option\ACLOptionList
	 */
	public function getOptions($objectTypeID, $categoryName = '') {
		$optionList = new ACLOptionList();
		if (!empty($categoryName)) {
			if (StringUtil::endsWith($categoryName, '.*')) {
				$categoryName = StringUtil::substring($categoryName, 0, -1) . '%';
				$optionList->getConditionBuilder()->add("acl_option.categoryName LIKE ?", array($categoryName));
			}
			else {
				$optionList->getConditionBuilder()->add("acl_option.categoryName = ?", array($categoryName));
			}
		}
		$optionList->getConditionBuilder()->add("acl_option.objectTypeID = ?", array($objectTypeID));
		$optionList->readObjects();
		
		return $optionList;
	}
开发者ID:0xLeon,项目名称:WCF,代码行数:23,代码来源:ACLHandler.class.php

示例8: getRequestURI

	/**
	 * Returns the request uri of the active request.
	 * 
	 * @return	string
	 */
	public static function getRequestURI() {
		$REQUEST_URI = '';
		
		$appendQueryString = true;
		if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], '.php') !== false) {
			$REQUEST_URI = $_SERVER['ORIG_PATH_INFO'];
		}
		else if (!empty($_SERVER['ORIG_SCRIPT_NAME'])) {
			$REQUEST_URI = $_SERVER['ORIG_SCRIPT_NAME'];
		}
		else if (!empty($_SERVER['SCRIPT_NAME']) && (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO']))) {
			$REQUEST_URI = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
		}
		else if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) {
			$REQUEST_URI = $_SERVER['REQUEST_URI'];
			$appendQueryString = false;
		}
		else if (!empty($_SERVER['PHP_SELF'])) {
			$REQUEST_URI = $_SERVER['PHP_SELF'];
		}
		else if (!empty($_SERVER['PATH_INFO'])) {
			$REQUEST_URI = $_SERVER['PATH_INFO'];
		}
		if ($appendQueryString && !empty($_SERVER['QUERY_STRING'])) {
			$REQUEST_URI .= '?'.$_SERVER['QUERY_STRING'];
		}
		
		// fix encoding
		if (!StringUtil::isASCII($REQUEST_URI) && !StringUtil::isUTF8($REQUEST_URI)) {
			$REQUEST_URI = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $REQUEST_URI);
		}
		
		return StringUtil::substring(FileUtil::unifyDirSeperator($REQUEST_URI), 0, 255);
	}
开发者ID:0xLeon,项目名称:WCF,代码行数:39,代码来源:UserUtil.class.php

示例9: import

	/**
	 * Imports a style.
	 * 
	 * @param	string		$filename
	 * @param	integer		$packageID
	 * @param	StyleEditor	$style
	 * @return	StyleEditor
	 */
	public static function import($filename, $packageID = PACKAGE_ID, StyleEditor $style = null) {
		// open file
		$tar = new Tar($filename);
		
		// get style data
		$data = self::readStyleData($tar);
		
		$styleData = array(
			'styleName' => $data['name'],
			'variables' => $data['variables'],
			'styleVersion' => $data['version'],
			'styleDate' => $data['date'],
			'copyright' => $data['copyright'],
			'license' => $data['license'],
			'authorName' => $data['authorName'],
			'authorURL' => $data['authorURL']
		);
		
		// create template group
		$templateGroupID = 0;
		if (!empty($data['templates'])) {
			$templateGroupName = $originalTemplateGroupName = $data['name'];
			$templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName);
			if (empty($templateGroupFolderName)) $templateGroupFolderName = 'generic'.StringUtil::substring(StringUtil::getRandomID(), 0, 8);
			$originalTemplateGroupFolderName = $templateGroupFolderName;
			
			// get unique template pack name
			$i = 1;
			while (true) {
				$sql = "SELECT	COUNT(*) AS count
					FROM	wcf".WCF_N."_template_group
					WHERE	templateGroupName = ?";
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute(array($templateGroupName));
				$row = $statement->fetchArray();
				if (!$row['count']) break;
				$templateGroupName = $originalTemplateGroupName . '_' . $i;
				$i++;
			}
			
			// get unique folder name
			$i = 1;
			while (true) {
				$sql = "SELECT	COUNT(*) AS count
					FROM	wcf".WCF_N."_template_group
					WHERE	templateGroupFolderName = ?
						AND parentTemplatePackID = ?";
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute(array(
					FileUtil::addTrailingSlash($templateGroupFolderName),
					0
				));
				$row = $statement->fetchArray();
				if (!$row['count']) break;
				$templateGroupFolderName = $originalTemplateGroupFolderName . '_' . $i;
				$i++;
			}
			
			$templateGroup = TemplateGroupEditor::create(array(
				'templateGroupName' => $templateGroupName,
				'templateGroupFolderName' => FileUtil::addTrailingSlash($templateGroupFolderName)
			));
			$styleData['templateGroupID'] = $templateGroup->templateGroupID;
		}
		
		// import preview image
		if (!empty($data['image'])) {
			$fileExtension = StringUtil::substring($data['image'], StringUtil::lastIndexOf($data['image'], '.'));
			$index = $tar->getIndexByFilename($data['image']);
			if ($index !== false) {
				$filename = WCF_DIR.'images/stylePreview-'.$style->styleID.'.'.$fileExtension;
				$tar->extract($index, $filename);
				@chmod($filename, 0777);
				
				if (file_exists($filename)) {
					$styleData['image'] = $filename;
				}
			}
		}
		
		// import images
		if (!empty($data['images']) && $data['imagesPath'] != 'images/') {
			// create images folder if necessary
			$imagesLocation = self::getFileLocation($data['imagesPath']);
			$styleData['imagePath'] = FileUtil::getRelativePath(WCF_DIR, $imagesLocation);
			
			$index = $tar->getIndexByFilename($data['images']);
			if ($index !== false) {
				// extract images tar
				$destination = FileUtil::getTemporaryFilename('images_');
				$tar->extract($index, $destination);
				
//.........这里部分代码省略.........
开发者ID:0xLeon,项目名称:WCF,代码行数:101,代码来源:StyleEditor.class.php

示例10: encodeAllChars

 /**
  * Returns html entities of all characters in the given string.
  * 
  * @param	string		$string
  * @return	string
  */
 public static function encodeAllChars($string)
 {
     $result = '';
     for ($i = 0, $j = StringUtil::length($string); $i < $j; $i++) {
         $char = StringUtil::substring($string, $i, 1);
         $result .= '&#' . StringUtil::getCharValue($char) . ';';
     }
     return $result;
 }
开发者ID:ZerGabriel,项目名称:WCF,代码行数:15,代码来源:StringUtil.class.php

示例11: __construct

 /**
  * Creates a new DatabaseObjectList object.
  */
 public function __construct()
 {
     // set class name
     if (empty($this->className)) {
         $className = get_called_class();
         if (StringUtil::substring($className, -4) == 'List') {
             $this->className = StringUtil::substring($className, 0, -4);
         }
     }
     $this->conditionBuilder = new PreparedStatementConditionBuilder();
 }
开发者ID:ZerGabriel,项目名称:WCF,代码行数:14,代码来源:DatabaseObjectList.class.php

示例12: __construct

	/**
	 * Initialize a new DatabaseObject-related action.
	 * 
	 * @param	array<mixed>	$objects
	 * @param	string		$action
	 * @param	array		$parameters
	 */
	public function __construct(array $objects, $action, array $parameters = array()) {
		// set class name
		if (empty($this->className)) {
			$className = get_called_class();
			
			if (StringUtil::substring($className, -6) == 'Action') {
				$this->className = StringUtil::substring($className, 0, -6).'Editor';
			}
		}
		
		$indexName = call_user_func(array($this->className, 'getDatabaseTableIndexName'));
		$baseClass = call_user_func(array($this->className, 'getBaseClass'));
		
		foreach ($objects as $object) {
			if (is_object($object)) {
				if ($object instanceof $this->className) {
					$this->objects[] = $object;
				}
				else if ($object instanceof $baseClass) {
					$this->objects[] = new $this->className($object);
				}
				else {
					throw new SystemException('invalid value of parameter objects given');
				}
				
				$this->objectIDs[] = $object->$indexName;
			}
			else {
				$this->objectIDs[] = $object;
			}
		}
		
		$this->action = $action;
		$this->parameters = $parameters;
		
		// fire event action
		EventHandler::getInstance()->fireAction($this, 'initializeAction');
	}
开发者ID:0xLeon,项目名称:WCF,代码行数:45,代码来源:AbstractDatabaseObjectAction.class.php

示例13: convertShorthandByteValue

	/**
	 * Converts shorthand byte values into an integer representing bytes.
	 * 
	 * @param	string		$value
	 * @return	integer
	 * @see		http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
	 */
	protected static function convertShorthandByteValue($value) {
		// convert into bytes
		$lastCharacter = StringUtil::substring($value, -1);
		switch ($lastCharacter) {
			// gigabytes
			case 'g':
				return (int)$value * 1073741824;
			break;
			
			// megabytes
			case 'm':
				return (int)$value * 1048576;
			break;
			
			// kilobytes
			case 'k':
				return (int)$value * 1024;
			break;
			
			default:
				return $value;
			break;
		}
	}
开发者ID:0xLeon,项目名称:WCF,代码行数:31,代码来源:PackageInstallationDispatcher.class.php

示例14: compileOutputTag

	/**
	 * Compiles an output tag and returns the compiled PHP code.
	 * 
	 * @param	string		$tag
	 * @return	string
	 */
	protected function compileOutputTag($tag) {
		$encodeHTML = false;
		$formatNumeric = false;
		if ($tag[0] == '@') {
			$tag = StringUtil::substring($tag, 1);
		}
		else if ($tag[0] == '#') {
			$tag = StringUtil::substring($tag, 1);
			$formatNumeric = true;
		}
		else {
			$encodeHTML = true;
		}
		
		$parsedTag = $this->compileVariableTag($tag);
		
		// the @ operator at the beginning of an output avoids
		// the default call of StringUtil::encodeHTML()
		if ($encodeHTML) {
			$parsedTag = 'wcf\util\StringUtil::encodeHTML('.$parsedTag.')';
		}
		// the # operator at the beginning of an output instructs
		// the complier to call the StringUtil::formatNumeric() method
		else if ($formatNumeric) {
			$parsedTag = 'wcf\util\StringUtil::formatNumeric('.$parsedTag.')';
		}
		
		return '<?php echo '.$parsedTag.'; ?>';
	}
开发者ID:0xLeon,项目名称:WCF,代码行数:35,代码来源:TemplateScriptingCompiler.class.php

示例15: getSchema

	/**
	 * Determines schema for given document.
	 */
	protected function getSchema() {
		// determine schema by looking for xsi:schemaLocation
		$this->schema = $this->document->documentElement->getAttributeNS($this->document->documentElement->lookupNamespaceURI('xsi'), 'schemaLocation');
		
		// no valid schema found or it's lacking a valid namespace
		if (strpos($this->schema, ' ') === false) {
			throw new SystemException("XML document '".$this->path."' does not provide a valid schema.");
		}
		
		// build file path upon namespace and filename
		$tmp = explode(' ', $this->schema);
		$this->schema = WCF_DIR.'xsd/'.StringUtil::substring(sha1($tmp[0]), 0, 8) . '_' . basename($tmp[1]);
		
		if (!file_exists($this->schema) || !is_readable($this->schema)) {
			throw new SystemException("Could not read XML schema definition located at '".$this->schema."'.");
		}
	}
开发者ID:0xLeon,项目名称:WCF,代码行数:20,代码来源:XML.class.php


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