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


PHP StringUtil::convertEncoding方法代码示例

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


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

示例1: parseKeywords

 /**
  * Parses search keywords.
  * 
  * @param	string		$keywordString
  */
 protected static function parseKeywords($keywordString)
 {
     // convert encoding if necessary
     if (CHARSET == 'UTF-8' && !StringUtil::isASCII($keywordString) && !StringUtil::isUTF8($keywordString)) {
         $keywordString = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $keywordString);
     }
     // remove bad wildcards
     $keywordString = preg_replace('/(?<!\\w)\\*/', '', $keywordString);
     // remove search operators
     $keywordString = preg_replace('/[\\+\\-><()~]+/', '', $keywordString);
     if (StringUtil::substring($keywordString, 0, 1) == '"' && StringUtil::substring($keywordString, -1) == '"') {
         // phrases search
         $keywordString = StringUtil::trim(StringUtil::substring($keywordString, 1, -1));
         if (!empty($keywordString)) {
             self::$keywords = array_merge(self::$keywords, array(StringUtil::encodeHTML($keywordString)));
         }
     } else {
         // replace word delimiters by space
         $keywordString = preg_replace('/[.,]/', ' ', $keywordString);
         $keywords = ArrayUtil::encodeHTML(ArrayUtil::trim(explode(' ', $keywordString)));
         if (count($keywords) > 0) {
             self::$keywords = array_merge(self::$keywords, $keywords);
         }
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:30,代码来源:KeywordHighlighter.class.php

示例2: getContentPreview

 /**
  * Returns an abstract of the file content.
  * 
  * @param	array		$data
  * @return	string
  */
 protected static function getContentPreview($data)
 {
     if (!ATTACHMENT_ENABLE_CONTENT_PREVIEW || $data['isBinary'] || $data['attachmentSize'] == 0) {
         return '';
     }
     $content = '';
     try {
         $file = new File(WCF_DIR . 'attachments/attachment-' . $data['attachmentID'], 'rb');
         $content = $file->read(2003);
         $file->close();
         if (CHARSET == 'UTF-8') {
             if (!StringUtil::isASCII($content) && !StringUtil::isUTF8($content)) {
                 $content = StringUtil::convertEncoding('ISO-8859-1', CHARSET, $content);
             }
             $content = StringUtil::substring($content, 0, 500);
             if (strlen($content) < $file->filesize()) {
                 $content .= '...';
             }
         } else {
             if (StringUtil::isUTF8($content)) {
                 return '';
             }
             $content = StringUtil::substring($content, 0, 500);
             if ($file->filesize() > 500) {
                 $content .= '...';
             }
         }
     } catch (Exception $e) {
     }
     // ignore errors
     return $content;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:38,代码来源:Attachments.class.php

示例3: getContentPreview

 /**
  * Returns an abstract of the file content.
  * 
  * @return	string
  */
 public function getContentPreview()
 {
     if ($this->contentPreview === null) {
         $this->contentPreview = '';
         if (ATTACHMENT_ENABLE_CONTENT_PREVIEW && !$this->isBinary && $this->attachmentSize != 0) {
             try {
                 $file = new File(WCF_DIR . 'attachments/attachment-' . $this->attachmentID, 'rb');
                 $this->contentPreview = $file->read(2003);
                 $file->close();
                 if (CHARSET == 'UTF-8') {
                     if (!StringUtil::isASCII($this->contentPreview) && !StringUtil::isUTF8($this->contentPreview)) {
                         $this->contentPreview = StringUtil::convertEncoding('ISO-8859-1', CHARSET, $this->contentPreview);
                     }
                     $this->contentPreview = StringUtil::substring($this->contentPreview, 0, 500);
                     if (strlen($this->contentPreview) < $file->filesize()) {
                         $this->contentPreview .= '...';
                     }
                 } else {
                     if (StringUtil::isUTF8($this->contentPreview)) {
                         $this->contentPreview = '';
                     } else {
                         $this->contentPreview = StringUtil::substring($this->contentPreview, 0, 500);
                         if ($file->filesize() > 500) {
                             $this->contentPreview .= '...';
                         }
                     }
                 }
             } catch (Exception $e) {
             }
             // ignore errors
         }
     }
     return $this->contentPreview;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:39,代码来源:Attachment.class.php

示例4: readParameters

 /**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_POST['query'])) {
         $this->query = StringUtil::trim($_POST['query']);
         if (CHARSET != 'UTF-8') {
             $this->query = StringUtil::convertEncoding('UTF-8', CHARSET, $this->query);
         }
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:13,代码来源:UserSuggestPage.class.php

示例5: readParameters

 /**
  * @see Action::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_POST['title'])) {
         $this->title = $_POST['title'];
         if (CHARSET != 'UTF-8') {
             $this->title = StringUtil::convertEncoding('UTF-8', CHARSET, $this->title);
         }
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:13,代码来源:BoardRenameAction.class.php

示例6: readParameters

 /**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['query'])) {
         $queryString = $_REQUEST['query'];
         if (CHARSET != 'UTF-8') {
             $queryString = StringUtil::convertEncoding('UTF-8', CHARSET, $queryString);
         }
         $this->query = ArrayUtil::trim(explode(',', $queryString));
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:14,代码来源:ContestJuryObjectsPage.class.php

示例7: readParameters

 /**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_POST['query'])) {
         $this->query = StringUtil::trim($_POST['query']);
         if (CHARSET != 'UTF-8') {
             $this->query = StringUtil::convertEncoding('UTF-8', CHARSET, $this->query);
         }
     }
     if (count(Language::getAvailableContentLanguages(PACKAGE_ID)) > 0) {
         $this->languageID = WCF::getLanguage()->getLanguageID();
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:16,代码来源:TagSuggestPage.class.php

示例8: readParameters

 /**
  * @see Action::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['packageID'])) {
         $this->packageID = intval($_REQUEST['packageID']);
     }
     if (isset($_POST['name'])) {
         $this->name = $_POST['name'];
         if (CHARSET != 'UTF-8') {
             $this->name = StringUtil::convertEncoding('UTF-8', CHARSET, $this->name);
         }
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:16,代码来源:PackageRenameAction.class.php

示例9: readParameters

 /**
  * @see Action::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['contestRatingoptionID'])) {
         $this->contestRatingoptionID = intval($_REQUEST['contestRatingoptionID']);
     }
     if (isset($_POST['title'])) {
         $this->title = $_POST['title'];
         if (CHARSET != 'UTF-8') {
             $this->title = StringUtil::convertEncoding('UTF-8', CHARSET, $this->title);
         }
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:16,代码来源:ContestRatingoptionRenameAction.class.php

示例10: readParameters

 /**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['query']) && isset($_REQUEST['text'])) {
         $querySubject = $_REQUEST['query'];
         $queryText = $_REQUEST['text'];
         if (CHARSET != 'UTF-8') {
             $querySubject = StringUtil::convertEncoding('UTF-8', CHARSET, $querySubject);
             $queryText = StringUtil::convertEncoding('UTF-8', CHARSET, $queryText);
         }
         $this->subject = $querySubject;
         $this->message = $queryText;
     }
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:17,代码来源:ContestPriceObjectsPage.class.php

示例11: readParameters

 /**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['postID'])) {
         $this->postID = ArrayUtil::toIntegerArray($_REQUEST['postID']);
     }
     if (isset($_REQUEST['threadID'])) {
         $this->threadID = intval($_REQUEST['threadID']);
     }
     if (isset($_REQUEST['reason'])) {
         $this->reason = StringUtil::trim($_REQUEST['reason']);
         if (CHARSET != 'UTF-8') {
             $this->reason = StringUtil::convertEncoding('UTF-8', CHARSET, $this->reason);
         }
     }
     if (isset($_REQUEST['boardID'])) {
         $this->boardID = intval($_REQUEST['boardID']);
     }
     if (isset($_REQUEST['topic'])) {
         $this->topic = StringUtil::trim($_REQUEST['topic']);
         if (CHARSET != 'UTF-8') {
             $this->topic = StringUtil::convertEncoding('UTF-8', CHARSET, $this->topic);
         }
     }
     if (isset($_REQUEST['url'])) {
         $this->url = $_REQUEST['url'];
     }
     // check permissions
     if (!is_array($this->postID) && $this->postID != 0) {
         require_once WBB_DIR . 'lib/data/post/PostEditor.class.php';
         $this->post = new PostEditor($this->postID);
         if (!$this->post->postID) {
             throw new IllegalLinkException();
         }
         $this->threadID = $this->post->threadID;
     }
     if ($this->threadID != 0) {
         require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php';
         $this->thread = new ThreadEditor($this->threadID);
         $this->boardID = $this->thread->boardID;
         $this->thread->enter();
     }
     if ($this->boardID != 0) {
         require_once WBB_DIR . 'lib/data/board/BoardEditor.class.php';
         $this->board = new BoardEditor($this->boardID);
         if ($this->thread != null) {
             $this->thread->enter();
         }
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:53,代码来源:PostActionPage.class.php

示例12: readParameters

 /**
  * @see Page::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['boardID'])) {
         $this->boardID = intval($_REQUEST['boardID']);
     }
     if (isset($_REQUEST['threadID'])) {
         $this->threadID = ArrayUtil::toIntegerArray($_REQUEST['threadID']);
     }
     if (isset($_REQUEST['reason'])) {
         $this->reason = StringUtil::trim($_REQUEST['reason']);
         if (CHARSET != 'UTF-8') {
             $this->reason = StringUtil::convertEncoding('UTF-8', CHARSET, $this->reason);
         }
     }
     if (isset($_REQUEST['topic'])) {
         $this->topic = StringUtil::trim($_REQUEST['topic']);
         if (CHARSET != 'UTF-8') {
             $this->topic = StringUtil::convertEncoding('UTF-8', CHARSET, $this->topic);
         }
     }
     if (isset($_REQUEST['prefix'])) {
         $this->prefix = $_REQUEST['prefix'];
         if (CHARSET != 'UTF-8') {
             $this->prefix = StringUtil::convertEncoding('UTF-8', CHARSET, $this->prefix);
         }
     }
     if (isset($_REQUEST['url'])) {
         $this->url = $_REQUEST['url'];
     }
     if (!is_array($this->threadID) && $this->threadID != 0) {
         $this->thread = new ThreadEditor($this->threadID);
         $this->boardID = $this->thread->boardID;
         if ($this->thread->movedThreadID) {
             $movedThread = new ThreadEditor($this->thread->movedThreadID);
             $movedThread->enter();
         } else {
             $this->thread->enter();
         }
     }
     if ($this->boardID != 0) {
         $this->board = new BoardEditor($this->boardID);
         if ($this->thread == null) {
             $this->board->enter();
         }
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:50,代码来源:ThreadActionPage.class.php

示例13: readParameters

 /**
  * @see Action::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     try {
         // get post
         if (isset($_REQUEST['postID'])) {
             $this->postID = intval($_REQUEST['postID']);
         }
         $this->post = new PostEditor($this->postID);
         if (!$this->post->postID) {
             throw new IllegalLinkException();
         }
         // get thread
         $this->thread = new ThreadEditor($this->post->threadID);
         $this->board = new BoardEditor($this->thread->boardID);
         $this->thread->enter($this->board);
         // check permissions
         $isModerator = $this->board->getModeratorPermission('canEditPost') || $this->board->getModeratorPermission('canDeletePost');
         $isAuthor = $this->post->userID && $this->post->userID == WCF::getUser()->userID;
         $canEditPost = $this->board->getModeratorPermission('canEditPost') || $isAuthor && $this->board->getPermission('canEditOwnPost');
         if (!$canEditPost || !$isModerator && ($this->board->isClosed || $this->thread->isClosed || $this->post->isClosed)) {
             throw new PermissionDeniedException();
         }
         // check post edit timeout
         if (!$isModerator && WCF::getUser()->getPermission('user.board.postEditTimeout') != -1 && TIME_NOW - $this->post->time > WCF::getUser()->getPermission('user.board.postEditTimeout') * 60) {
             throw new NamedUserException(WCF::getLanguage()->get('wbb.postEdit.error.timeout', array('$timeout' => WCF::getUser()->getPermission('user.board.postEditTimeout'))));
         }
         // get message
         if (isset($_POST['text'])) {
             $this->text = StringUtil::trim($_POST['text']);
             if (CHARSET != 'UTF-8') {
                 $this->text = StringUtil::convertEncoding('UTF-8', CHARSET, $this->text);
             }
             if (empty($this->text)) {
                 throw new IllegalLinkException();
             }
         }
     } catch (UserException $e) {
         @header('HTTP/1.0 403 Forbidden');
         echo $e->getMessage();
         exit;
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:46,代码来源:PostMessageEditAction.class.php

示例14: loadLanguage

 /**
  * Loads the compiled language file.
  * Compiles the language file before if necessary.
  */
 public function loadLanguage()
 {
     $this->languageLoaded = true;
     $filename = TMP_DIR . TMP_FILE_PREFIX . $this->data['languageCode'] . '_' . $this->data['languageEncoding'] . '_wcf.setup.php';
     if (!file_exists($filename)) {
         $xml = new XML(TMP_DIR . TMP_FILE_PREFIX . 'setup_' . $this->data['languageCode'] . '.xml');
         // compile an array with XML::getElementTree
         $languageXML = $xml->getElementTree('language');
         // extract attributes (language code, language name)
         //$languageXML = array_merge($languageXML, $languageXML['attrs']);
         // get language items
         $categoriesToCache = array();
         foreach ($languageXML['children'] as $key => $languageCategory) {
             // language category does not exist yet, create it
             if (isset($languageCategory['children'])) {
                 foreach ($languageCategory['children'] as $key2 => $languageitem) {
                     $categoriesToCache[] = array('name' => $languageitem['attrs']['name'], 'cdata' => $languageitem['cdata']);
                 }
             }
         }
         // update language files here
         if (count($categoriesToCache) > 0) {
             $file = new File($filename);
             $file->write("<?php\n/**\n* WoltLab Community Framework\n* language: " . $this->data['languageCode'] . "\n* encoding: " . $this->data['languageEncoding'] . "\n* category: WCF Setup\n* generated at " . gmdate("r") . "\n* \n* DO NOT EDIT THIS FILE\n*/\n");
             foreach ($categoriesToCache as $value => $name) {
                 // simple_xml returns values always UTF-8 encoded
                 // manual decoding to charset necessary
                 if ($this->data['languageEncoding'] != 'UTF-8') {
                     $name['cdata'] = StringUtil::convertEncoding('UTF-8', $this->data['languageEncoding'], $name['cdata']);
                 }
                 $file->write("\$this->items[\$this->languageID]['" . $name['name'] . "'] = '" . str_replace("'", "\\'", $name['cdata']) . "';\n");
                 // compile dynamic language variables
                 if (strpos($name['cdata'], '{') !== false) {
                     $file->write("\$this->dynamicItems[\$this->languageID]['" . $name['name'] . "'] = '" . str_replace("'", "\\'", self::getScriptingCompiler()->compileString($name['name'], $name['cdata'])) . "';\n");
                 }
             }
             $file->write("?>");
             $file->close();
         }
     }
     include_once $filename;
     $this->setLocale();
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:47,代码来源:SetupLanguage.class.php

示例15: __construct

 /**
  * Creates a new PackageUpdateAuthForm object.
  * 
  * @param	PackageUpdateAuthorizationRequiredException	$exception
  */
 public function __construct($exception = null)
 {
     $this->exception = $exception;
     if ($this->exception !== null) {
         $this->packageUpdateServerID = $this->exception->getPackageUpdateServerID();
         $this->url = $this->exception->getURL();
         $this->header = $this->exception->getResponseHeader();
         // get message
         $this->message = $this->exception->getResponseContent();
         // find out response charset
         if (preg_match('/charset=([a-z0-9\\-]+)/i', $this->header, $match)) {
             $charset = strtoupper($match[1]);
             if ($charset != CHARSET) {
                 $this->message = @StringUtil::convertEncoding($charset, CHARSET, $this->message);
             }
         }
         // format message
         $this->message = nl2br(preg_replace("/\n{3,}/", "\n\n", StringUtil::unifyNewlines(StringUtil::trim(strip_tags($this->message)))));
     }
     parent::__construct();
 }
开发者ID:CaribeSoy,项目名称:contest-wcf,代码行数:26,代码来源:PackageUpdateAuthForm.class.php


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