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


PHP Spoon::getCharsets方法代码示例

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


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

示例1: urlise

 /**
  * Prepares a string so that it can be used in urls. Special characters are stripped/replaced.
  *
  * @return	string						The urlised string.
  * @param	string $value				The value that should be urlised.
  * @param	string[optional] $charset	The charset to use, default is based on SPOON_CHARSET.
  */
 public static function urlise($value, $charset = null)
 {
     // define charset
     $charset = $charset !== null ? self::getValue($charset, Spoon::getCharsets(), SPOON_CHARSET) : SPOON_CHARSET;
     // allowed characters
     $characters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_', ' ');
     // redefine value
     $value = mb_strtolower($value, $charset);
     // replace special characters
     $replace = array();
     $replace['.'] = ' ';
     $replace['@'] = ' at ';
     $replace['©'] = ' copyright ';
     $replace['€'] = ' euro ';
     $replace['™'] = ' tm ';
     // replace special characters
     $value = str_replace(array_keys($replace), array_values($replace), $value);
     // reform non ascii characters
     $value = iconv($charset, 'ASCII//TRANSLIT//IGNORE', $value);
     // remove spaces at the beginning and the end
     $value = trim($value);
     // default endvalue
     $newValue = '';
     // loop charachtesr
     for ($i = 0; $i < mb_strlen($value, $charset); $i++) {
         // valid character (so add to new string)
         if (in_array(mb_substr($value, $i, 1, $charset), $characters)) {
             $newValue .= mb_substr($value, $i, 1, $charset);
         }
     }
     // replace spaces by dashes
     $newValue = str_replace(' ', '-', $newValue);
     // there IS a value
     if (strlen($newValue) != 0) {
         // convert "--" to "-"
         $newValue = preg_replace('/\\-+/', '-', $newValue);
     }
     // trim - signs
     return trim($newValue, '-');
 }
开发者ID:JonckheereM,项目名称:Public,代码行数:47,代码来源:filter.php

示例2: urlise

 /**
  * Prepares a string so that it can be used in urls.
  *
  * @return	string						The urlised string.
  * @param	string $value				The value that should be urlised.
  * @param	string[optional] $charset	The charset to use, default is based on SPOON_CHARSET.
  */
 public static function urlise($value, $charset = null)
 {
     // define charset
     $charset = $charset !== null ? self::getValue($charset, Spoon::getCharsets(), SPOON_CHARSET) : SPOON_CHARSET;
     // reserved characters (RFC 3986)
     $reservedCharacters = array('/', '?', ':', '@', '#', '[', ']', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=');
     // remove reserved characters
     $value = str_replace($reservedCharacters, ' ', $value);
     // replace double quote, since this one might cause problems in html (e.g. <a href="double"quote">)
     $value = str_replace('"', ' ', $value);
     // replace spaces by dashes
     $value = str_replace(' ', '-', $value);
     // only urlencode if not yet urlencoded
     if (urldecode($value) == $value) {
         // to lowercase
         $value = mb_strtolower($value, $charset);
         // urlencode
         $value = urlencode($value);
     }
     // convert "--" to "-"
     $value = preg_replace('/\\-+/', '-', $value);
     // trim - signs
     return trim($value, '-');
 }
开发者ID:sunkangtaichi,项目名称:library,代码行数:31,代码来源:filter.php

示例3: setCharset

 /**
  * Set the charset.
  *
  * @param	string[optional] $charset	The charset that should be used. Possible charsets can be found in spoon.php.
  */
 public function setCharset($charset = 'utf-8')
 {
     $this->charset = SpoonFilter::getValue($charset, Spoon::getCharsets(), SPOON_CHARSET);
 }
开发者ID:jincongho,项目名称:clienthub,代码行数:9,代码来源:rss.php

示例4: setCharset

 /**
  * Changes the charset from standard utf-8 to your preferred value.
  *
  * @param	string[optional] $charset	The charset to use, default is utf-8.
  */
 public function setCharset($charset = 'utf-8')
 {
     $this->charset = $charset !== null ? SpoonFilter::getValue($charset, Spoon::getCharsets(), Spoon::getCharset()) : Spoon::getCharset();
 }
开发者ID:jeroendesloovere,项目名称:library,代码行数:9,代码来源:email.php


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