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


PHP StringHelper::byteSubstr方法代码示例

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


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

示例1: testSubstr

 public function testSubstr()
 {
     $this->assertEquals('th', StringHelper::byteSubstr('this', 0, 2));
     $this->assertEquals('э', StringHelper::byteSubstr('это', 0, 2));
     $this->assertEquals('abcdef', StringHelper::byteSubstr('abcdef', 0));
     $this->assertEquals('abcdef', StringHelper::byteSubstr('abcdef', 0, null));
     $this->assertEquals('de', StringHelper::byteSubstr('abcdef', 3, 2));
     $this->assertEquals('def', StringHelper::byteSubstr('abcdef', 3));
     $this->assertEquals('def', StringHelper::byteSubstr('abcdef', 3, null));
     $this->assertEquals('cd', StringHelper::byteSubstr('abcdef', -4, 2));
     $this->assertEquals('cdef', StringHelper::byteSubstr('abcdef', -4));
     $this->assertEquals('cdef', StringHelper::byteSubstr('abcdef', -4, null));
     $this->assertEquals('', StringHelper::byteSubstr('abcdef', 4, 0));
     $this->assertEquals('', StringHelper::byteSubstr('abcdef', -4, 0));
     $this->assertEquals('это', StringHelper::byteSubstr('это', 0));
     $this->assertEquals('это', StringHelper::byteSubstr('это', 0, null));
     $this->assertEquals('т', StringHelper::byteSubstr('это', 2, 2));
     $this->assertEquals('то', StringHelper::byteSubstr('это', 2));
     $this->assertEquals('то', StringHelper::byteSubstr('это', 2, null));
     $this->assertEquals('т', StringHelper::byteSubstr('это', -4, 2));
     $this->assertEquals('то', StringHelper::byteSubstr('это', -4));
     $this->assertEquals('то', StringHelper::byteSubstr('это', -4, null));
     $this->assertEquals('', StringHelper::byteSubstr('это', 4, 0));
     $this->assertEquals('', StringHelper::byteSubstr('это', -4, 0));
 }
开发者ID:aivavic,项目名称:yii2,代码行数:25,代码来源:StringHelperTest.php

示例2: compTokens

 public static function compTokens($token, $trueToken)
 {
     $token = base64_decode(str_replace('.', '+', $token));
     $n = StringHelper::byteLength($token);
     if ($n <= static::CSRF_MASK_LENGTH) {
         return false;
     }
     $mask = StringHelper::byteSubstr($token, 0, static::CSRF_MASK_LENGTH);
     $token = StringHelper::byteSubstr($token, static::CSRF_MASK_LENGTH, $n - static::CSRF_MASK_LENGTH);
     $token = static::xorTokens($mask, $token);
     return $token === $trueToken;
 }
开发者ID:semnt,项目名称:tp01,代码行数:12,代码来源:Csrf.php

示例3: moveToUpload

 /**
  * @return string|false
  */
 public function moveToUpload()
 {
     $filename = sha1(microtime());
     $ext = pathinfo($this->getName(), PATHINFO_EXTENSION);
     $upload_path = File\Module::module()->upload_path;
     $p1 = StringHelper::byteSubstr($filename, 0, 2);
     $p2 = StringHelper::byteSubstr($filename, 2, 2);
     $path = $upload_path . DIRECTORY_SEPARATOR . $p1 . DIRECTORY_SEPARATOR . $p2;
     if (!file_exists($path)) {
         FileHelper::createDirectory($path);
     }
     $file_path = $path . DIRECTORY_SEPARATOR . $filename . '.' . $ext;
     $result = copy($this->getTemp(), $file_path);
     $this->clear();
     chmod($file_path, 0664);
     return $result === true ? $file_path : false;
 }
开发者ID:rmrevin,项目名称:yii2-file,代码行数:20,代码来源:AbstractResource.php

示例4: setDomains

 /**
  *
  * @param string $url
  * @return self
  */
 protected static function setDomains($url)
 {
     self::$baseFolder = '';
     if (empty(self::$homeUrl)) {
         self::$homeUrl = rtrim(StringHelper::dirname($_SERVER['PHP_SELF']), '/');
     }
     if (empty(self::$baseFolder)) {
         if ($str = mb_stristr(self::$homeUrl, 'admin', TRUE)) {
             self::$baseFolder = $str . "admin";
         }
         if ($str == false && !empty(self::$homeUrl)) {
             self::$baseFolder = rtrim(self::$homeUrl, '/');
         }
         self::$baseFolder = rtrim(self::$baseFolder, '/');
     }
     $url = StringHelper::byteSubstr($url, StringHelper::byteLength(self::$baseFolder), StringHelper::byteLength($url));
     self::$domains = explode('/', ltrim($url, '/'));
     return self::$domains;
 }
开发者ID:filamentv,项目名称:yii2-multilang,代码行数:24,代码来源:MultiLanguage.php

示例5: generateRandomKey

 /**
  * Generates specified number of random bytes.
  * Note that output may not be ASCII.
  * @see generateRandomString() if you need a string.
  *
  * @param integer $length the number of bytes to generate
  * @return string the generated random bytes
  * @throws InvalidConfigException if OpenSSL extension is required (e.g. on Windows) but not installed.
  * @throws Exception on failure.
  */
 public function generateRandomKey($length = 32)
 {
     /*
      * Strategy
      *
      * The most common platform is Linux, on which /dev/urandom is the best choice. Many other OSs
      * implement a device called /dev/urandom for Linux compat and it is good too. So if there is
      * a /dev/urandom then it is our first choice regardless of OS.
      *
      * Nearly all other modern Unix-like systems (the BSDs, Unixes and OS X) have a /dev/random
      * that is a good choice. If we didn't get bytes from /dev/urandom then we try this next but
      * only if the system is not Linux. Do not try to read /dev/random on Linux.
      *
      * Finally, OpenSSL can supply CSPR bytes. It is our last resort. On Windows this reads from
      * CryptGenRandom, which is the right thing to do. On other systems that don't have a Unix-like
      * /dev/urandom, it will deliver bytes from its own CSPRNG that is seeded from kernel sources
      * of randomness. Even though it is fast, we don't generally prefer OpenSSL over /dev/urandom
      * because an RNG in user space memory is undesirable.
      *
      * For background, see http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/
      */
     $bytes = '';
     // If we are on Linux or any OS that mimics the Linux /dev/urandom device, e.g. FreeBSD or OS X,
     // then read from /dev/urandom.
     if (@file_exists('/dev/urandom')) {
         $handle = fopen('/dev/urandom', 'r');
         if ($handle !== false) {
             $bytes .= fread($handle, $length);
             fclose($handle);
         }
     }
     if (StringHelper::byteLength($bytes) >= $length) {
         return StringHelper::byteSubstr($bytes, 0, $length);
     }
     // If we are not on Linux and there is a /dev/random device then we have a BSD or Unix device
     // that won't block. It's not safe to read from /dev/random on Linux.
     if (PHP_OS !== 'Linux' && @file_exists('/dev/random')) {
         $handle = fopen('/dev/random', 'r');
         if ($handle !== false) {
             $bytes .= fread($handle, $length);
             fclose($handle);
         }
     }
     if (StringHelper::byteLength($bytes) >= $length) {
         return StringHelper::byteSubstr($bytes, 0, $length);
     }
     if (!extension_loaded('openssl')) {
         throw new InvalidConfigException('The OpenSSL PHP extension is not installed.');
     }
     $bytes .= openssl_random_pseudo_bytes($length, $cryptoStrong);
     if (StringHelper::byteLength($bytes) < $length || !$cryptoStrong) {
         throw new Exception('Unable to generate random bytes.');
     }
     return StringHelper::byteSubstr($bytes, 0, $length);
 }
开发者ID:Jaaviieer,项目名称:PrograWeb,代码行数:65,代码来源:Security.php

示例6: sendContentAsFile

 /**
  * Sends the specified content as a file to the browser.
  *
  * Note that this method only prepares the response for file sending. The file is not sent
  * until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action.
  *
  * @param string $content the content to be sent. The existing [[content]] will be discarded.
  * @param string $attachmentName the file name shown to the user.
  * @param string $mimeType the MIME type of the content.
  * @return static the response object itself
  * @throws HttpException if the requested range is not satisfiable
  */
 public function sendContentAsFile($content, $attachmentName, $mimeType = 'application/octet-stream')
 {
     $headers = $this->getHeaders();
     $contentLength = StringHelper::byteLength($content);
     $range = $this->getHttpRange($contentLength);
     if ($range === false) {
         $headers->set('Content-Range', "bytes */{$contentLength}");
         throw new HttpException(416, 'Requested range not satisfiable');
     }
     $headers->setDefault('Pragma', 'public')->setDefault('Accept-Ranges', 'bytes')->setDefault('Expires', '0')->setDefault('Content-Type', $mimeType)->setDefault('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')->setDefault('Content-Transfer-Encoding', 'binary')->setDefault('Content-Length', StringHelper::byteLength($content))->setDefault('Content-Disposition', "attachment; filename=\"{$attachmentName}\"");
     list($begin, $end) = $range;
     if ($begin != 0 || $end != $contentLength - 1) {
         $this->setStatusCode(206);
         $headers->set('Content-Range', "bytes {$begin}-{$end}/{$contentLength}");
         $this->content = StringHelper::byteSubstr($content, $begin, $end - $begin + 1);
     } else {
         $this->setStatusCode(200);
         $this->content = $content;
     }
     $this->format = self::FORMAT_RAW;
     return $this;
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:34,代码来源:Response.php

示例7: parseExcludePattern

 /**
  * Processes the pattern, stripping special characters like / and ! from the beginning and settings flags instead.
  * @param string $pattern
  * @param boolean $caseSensitive
  * @throws \yii\base\InvalidParamException
  * @return array with keys: (string) pattern, (int) flags, (int|boolean)firstWildcard
  */
 private static function parseExcludePattern($pattern, $caseSensitive)
 {
     if (!is_string($pattern)) {
         throw new InvalidParamException('Exclude/include pattern must be a string.');
     }
     $result = ['pattern' => $pattern, 'flags' => 0, 'firstWildcard' => false];
     if (!$caseSensitive) {
         $result['flags'] |= self::PATTERN_CASE_INSENSITIVE;
     }
     if (!isset($pattern[0])) {
         return $result;
     }
     if ($pattern[0] == '!') {
         $result['flags'] |= self::PATTERN_NEGATIVE;
         $pattern = StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern));
     }
     if (StringHelper::byteLength($pattern) && StringHelper::byteSubstr($pattern, -1, 1) == '/') {
         $pattern = StringHelper::byteSubstr($pattern, 0, -1);
         $result['flags'] |= self::PATTERN_MUSTBEDIR;
     }
     if (strpos($pattern, '/') === false) {
         $result['flags'] |= self::PATTERN_NODIR;
     }
     $result['firstWildcard'] = self::firstWildcardInPattern($pattern);
     if ($pattern[0] == '*' && self::firstWildcardInPattern(StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern))) === false) {
         $result['flags'] |= self::PATTERN_ENDSWITH;
     }
     $result['pattern'] = $pattern;
     return $result;
 }
开发者ID:aoopvn,项目名称:EduSec4.0.0,代码行数:37,代码来源:BaseFileHelper.php

示例8: sendContentAsFile

 /**
  * Sends the specified content as a file to the browser.
  *
  * Note that this method only prepares the response for file sending. The file is not sent
  * until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action.
  *
  * @param string $content the content to be sent. The existing [[content]] will be discarded.
  * @param string $attachmentName the file name shown to the user.
  * @param array $options additional options for sending the file. The following options are supported:
  *
  *  - `mimeType`: the MIME type of the content. Defaults to 'application/octet-stream'.
  *  - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false,
  *    meaning a download dialog will pop up.
  *
  * @return $this the response object itself
  * @throws HttpException if the requested range is not satisfiable
  * @see sendFile() for an example implementation.
  */
 public function sendContentAsFile($content, $attachmentName, $options = [])
 {
     $headers = $this->getHeaders();
     $contentLength = StringHelper::byteLength($content);
     $range = $this->getHttpRange($contentLength);
     if ($range === false) {
         $headers->set('Content-Range', "bytes */{$contentLength}");
         throw new HttpException(416, 'Requested range not satisfiable');
     }
     list($begin, $end) = $range;
     if ($begin != 0 || $end != $contentLength - 1) {
         $this->setStatusCode(206);
         $headers->set('Content-Range', "bytes {$begin}-{$end}/{$contentLength}");
         $this->content = StringHelper::byteSubstr($content, $begin, $end - $begin + 1);
     } else {
         $this->setStatusCode(200);
         $this->content = $content;
     }
     $mimeType = isset($options['mimeType']) ? $options['mimeType'] : 'application/octet-stream';
     $this->setDownloadHeaders($attachmentName, $mimeType, !empty($options['inline']), $end - $begin + 1);
     $this->format = self::FORMAT_RAW;
     return $this;
 }
开发者ID:nanodesu88,项目名称:yii2,代码行数:41,代码来源:Response.php

示例9: addContent

 /**
  * Adds string content to the upload.
  * This method can invoked several times before [[complete()]] is called.
  * @param string $content binary content.
  * @return $this self reference.
  */
 public function addContent($content)
 {
     $freeBufferLength = $this->chunkSize - StringHelper::byteLength($this->buffer);
     $contentLength = StringHelper::byteLength($content);
     if ($contentLength > $freeBufferLength) {
         $this->buffer .= StringHelper::byteSubstr($content, 0, $freeBufferLength);
         $this->flushBuffer(true);
         return $this->addContent(StringHelper::byteSubstr($content, $freeBufferLength));
     } else {
         $this->buffer .= $content;
         $this->flushBuffer();
     }
     return $this;
 }
开发者ID:mootensai,项目名称:yii2-mongodb,代码行数:20,代码来源:Upload.php

示例10: getImageByUri

 /**
  * Get full path to image by Uri
  *
  * @param string $url Uri
  * @return string
  */
 public function getImageByUri($url)
 {
     $return = false;
     $url = (string) parse_url($url, PHP_URL_PATH);
     $file = StringHelper::basename($url, '.' . $this->config['extension']);
     if (32 > (int) StringHelper::byteLength($file)) {
         return $return;
     }
     $fileName = StringHelper::byteSubstr($file, 0, 32);
     $suffix = StringHelper::byteSubstr($file, 32);
     if ($result = $this->arcresultOne($fileName)) {
         $dirName = dirname($result->path);
         $targetPath = FileHelper::normalizePath(\Yii::getAlias($this->config['directories']['target'] . $dirName));
         $sourceFile = $targetPath . DIRECTORY_SEPARATOR . $fileName . '.' . $this->config['extension'];
         if (is_file($sourceFile)) {
             $return = $sourceFile;
         }
         if (empty($suffix)) {
             return $return;
         }
         $itemData = ['extension' => $this->config['extension'], 'quality' => (int) $this->config['quality'], 'file' => $fileName, 'source' => $sourceFile, 'directories' => ['source' => $targetPath, 'target' => $targetPath], 'targets' => []];
         if (false === is_file($itemData['source'])) {
             if ($files = glob($targetPath . DIRECTORY_SEPARATOR . $fileName . '*')) {
                 $fileSize = 0;
                 foreach ($files as $file) {
                     if ($fileSize < filesize($file)) {
                         $itemData['source'] = $file;
                         $fileSize = filesize($file);
                     }
                 }
             }
         }
         if (is_file($itemData['source'])) {
             if (false === empty($this->config['targets'])) {
                 foreach ($this->config['targets'] as $name => $target) {
                     if (isset($target['suffix']) && $suffix === $target['suffix']) {
                         $itemData['targets'][$name] = $target;
                         break;
                     }
                 }
             }
             if (empty($itemData['targets'])) {
                 if (false === empty($this->config['commands'])) {
                     $status = false;
                     foreach ($this->config['commands'] as $command) {
                         if (false === empty($command['targets'])) {
                             foreach ($command['targets'] as $name => $target) {
                                 if (isset($target['suffix']) && $suffix === $target['suffix']) {
                                     $itemData['targets'][$name] = $target;
                                     $status = true;
                                     break;
                                 }
                             }
                         }
                         if ($status) {
                             break;
                         }
                     }
                 }
             }
             if ($this->makeFile($itemData)) {
                 if (is_file($targetPath . DIRECTORY_SEPARATOR . basename($url))) {
                     $return = $targetPath . DIRECTORY_SEPARATOR . basename($url);
                 }
             }
         }
     }
     return $return;
 }
开发者ID:phantom-d,项目名称:yii2-file-daemon,代码行数:75,代码来源:ImageProcessing.php

示例11: getAbsolutePath

 /**
  * @return string
  */
 public function getAbsolutePath()
 {
     $upload_path = \rmrevin\yii\module\File\Module::module()->upload_path;
     $p1 = StringHelper::byteSubstr($this->name, 0, 2);
     $p2 = StringHelper::byteSubstr($this->name, 2, 2);
     return $upload_path . DIRECTORY_SEPARATOR . $p1 . DIRECTORY_SEPARATOR . $p2 . DIRECTORY_SEPARATOR . $this->name;
 }
开发者ID:rmrevin,项目名称:yii2-file,代码行数:10,代码来源:File.php

示例12:

                            </div>
                        </div>

                        <div class="col-xs-12 col-sm-10 blog-content">
                            <?php 
    $img = Html::img('@web/images/blog/' . Html::encode($page->cover_image), ['class' => 'img-responsive img-blog', 'width' => '100%']);
    ?>
                            <?php 
    echo Html::a($img, ['page/view', 'id' => $page->id]);
    ?>
                            <h2><?php 
    echo Html::a(Html::encode($page->title), ['page/view', 'id' => $page->id]);
    ?>
</h2>
                            <h3><?php 
    echo Html::encode(StringHelper::byteSubstr($page->content, 0, 215));
    ?>
...</h3>
                            <?php 
    echo Html::a('Read More', ['page/view', 'id' => $page->id], ['class' => 'btn btn-primary readmore']);
    ?>
                        </div>
                    </div>    
                </div><!--/.blog-item-->
                <?php 
}
?>

                <?php 
echo LinkPager::widget(['pagination' => $pagination, 'prevPageLabel' => 'Previous Page', 'nextPageLabel' => 'Next Page']);
?>
开发者ID:BorisMatonickin,项目名称:yiicms,代码行数:31,代码来源:index.php

示例13: parseInputStringValue

 /**
  * The method internally called in [[self::parseInputValue()]] and parse only string typed value.
  * @see [[self::parseInputValue()]]
  * @param string $value
  * @return string|null
  */
 protected function parseInputStringValue($value)
 {
     if ($value === '') {
         return null;
     }
     if (StringHelper::startsWith($value, $this->postParamUploadPrefix)) {
         $charset = Yii::$app->charset;
         $storagePrefixPos = mb_strpos($value, $this->postParamStoragePrefix, 0, $charset);
         $uploadPrefixLength = mb_strlen($this->postParamUploadPrefix, $charset);
         $valueLength = mb_strlen($value, $charset);
         $length = $storagePrefixPos === false ? $valueLength - $uploadPrefixLength : $storagePrefixPos - $uploadPrefixLength;
         $formName = mb_substr($value, $uploadPrefixLength, $length, $charset);
         if ($result = UploadedFile::getInstanceByName($formName)) {
             return $result;
         }
         if ($storagePrefixPos !== false) {
             $storagePrefixLength = mb_strlen($this->postParamStoragePrefix, $charset);
             $pos = $storagePrefixPos + $storagePrefixLength;
             $storageFileData = mb_substr($value, $pos, $valueLength - $pos, $charset);
         }
     }
     if (!isset($storageFileData) && StringHelper::startsWith($value, $this->postParamStoragePrefix)) {
         $storageFileData = StringHelper::byteSubstr($value, StringHelper::byteLength($this->postParamStoragePrefix));
     }
     if (isset($storageFileData) && $this->getStorage()->fileExists($storageFileData)) {
         return $storageFileData;
     }
     return null;
 }
开发者ID:alex-dwt,项目名称:file,代码行数:35,代码来源:Context.php

示例14: getImportContent

 /**
  * @param string $url
  *
  * @return null|string
  */
 private function getImportContent($url)
 {
     $result = null;
     if ('url(' === helpers\StringHelper::byteSubstr($url, 0, 4)) {
         $url = str_replace(['url(\'', 'url("', 'url(', '\')', '")', ')'], '', $url);
         if (helpers\StringHelper::byteSubstr($url, 0, 2) === '//') {
             $url = preg_replace('|^//|', 'http://', $url, 1);
         }
         $url = $this->rel2abs($url, Url::home(true));
         //var_dump($this->rel2abs($url, 'http://welooking.local'));
         //var_dump($url);
         if (!empty($url)) {
             $result = file_get_contents($url);
         }
     }
     return $result;
 }
开发者ID:appmake,项目名称:yii2-minify-view,代码行数:22,代码来源:View.php

示例15: substr

 /**
  * Return part of a file.
  * @param int $start reading start position.
  * If non-negative, the returned string will start at the start'th position in file, counting from zero.
  * If negative, the returned string will start at the start'th character from the end of file.
  * @param int $length number of bytes to read.
  * If given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of file).
  * If given and is negative, then that many characters will be omitted from the end of file (after the start position has been calculated when a start is negative).
  * @return string|false the extracted part of file or `false` on failure
  */
 public function substr($start, $length)
 {
     $document = $this->getDocument();
     if ($start < 0) {
         $start = max($document['length'] + $start, 0);
     }
     if ($start > $document['length']) {
         return false;
     }
     if ($length < 0) {
         $length = $document['length'] - $start + $length;
         if ($length < 0) {
             return false;
         }
     }
     $chunkSize = $document['chunkSize'];
     $startChunkNumber = floor($start / $chunkSize);
     $chunkIterator = $this->getChunkIterator();
     if (!$chunkIterator->valid()) {
         // invalid iterator state - recreate iterator
         // unable to use `rewind` due to error "Cursors cannot rewind after starting iteration"
         $chunkIterator = $this->getChunkIterator(true);
     }
     if ($chunkIterator->key() > $startChunkNumber) {
         // unable to go back by iterator
         // unable to use `rewind` due to error "Cursors cannot rewind after starting iteration"
         $chunkIterator = $this->getChunkIterator(true);
     }
     $result = '';
     $chunkDataOffset = $start - $startChunkNumber * $chunkSize;
     while ($chunkIterator->valid()) {
         if ($chunkIterator->key() >= $startChunkNumber) {
             $chunk = $chunkIterator->current();
             $data = $chunk['data']->getData();
             $readLength = min($chunkSize - $chunkDataOffset, $length);
             $result .= StringHelper::byteSubstr($data, $chunkDataOffset, $readLength);
             $length -= $readLength;
             if ($length <= 0) {
                 break;
             }
             $chunkDataOffset = 0;
         }
         $chunkIterator->next();
     }
     return $result;
 }
开发者ID:yiisoft,项目名称:yii2-mongodb,代码行数:56,代码来源:Download.php


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