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


PHP str::trim方法代码示例

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


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

示例1: sanitize

 /** 
  * A set of sanitizer methods
  * 
  * @param  string  $string The string to sanitize
  * @param  string  $type The method
  * @param  string  $default The default value if the string will be empty afterwards
  * @return string  The sanitized string
  */
 static function sanitize($string, $type = 'str', $default = null)
 {
     $string = stripslashes((string) $string);
     $string = urldecode($string);
     $string = str::utf8($string);
     switch ($type) {
         case 'int':
             $string = (int) $string;
             break;
         case 'str':
             $string = (string) $string;
             break;
         case 'array':
             $string = (array) $string;
             break;
         case 'nohtml':
             $string = self::unhtml($string);
             break;
         case 'noxml':
             $string = self::unxml($string);
             break;
         case 'enum':
             $string = in_array($string, array('y', 'n')) ? $string : $default;
             $string = in_array($string, array('y', 'n')) ? $string : 'n';
             break;
         case 'checkbox':
             $string = $string == 'on' ? 'y' : 'n';
             break;
         case 'url':
             $string = v::url($string) ? $string : '';
             break;
         case 'email':
             $string = v::email($string) ? $string : '';
             break;
         case 'plain':
             $string = str::unxml($string);
             $string = str::unhtml($string);
             $string = str::trim($string);
             break;
         case 'lower':
             $string = str::lower($string);
             break;
         case 'upper':
             $string = str::upper($string);
             break;
         case 'words':
             $string = str::sanitize($string, 'plain');
             $string = preg_replace('/[^\\pL]/u', ' ', $string);
         case 'tags':
             $string = str::sanitize($string, 'plain');
             $string = preg_replace('/[^\\pL\\pN]/u', ' ', $string);
             $string = str::trim($string);
         case 'nobreaks':
             $string = str_replace('\\n', '', $string);
             $string = str_replace('\\r', '', $string);
             $string = str_replace('\\t', '', $string);
             break;
         case 'url':
             $string = self::urlify($string);
             break;
         case 'filename':
             $string = f::safe_name($string);
             break;
     }
     return trim($string);
 }
开发者ID:sdvig,项目名称:kirbycms,代码行数:74,代码来源:kirby.php

示例2: languageSetup

 function languageSetup()
 {
     // check for activated language support
     if (!c::get('lang.support')) {
         return false;
     }
     // get the available languages
     $available = c::get('lang.available');
     // sanitize the available languages
     if (!is_array($available)) {
         // switch off language support
         c::set('lang.support', false);
         return false;
     }
     // get the raw uri
     $uri = uri::raw();
     // get the current language code
     $code = a::first(explode('/', $uri));
     // try to detect the language code if the code is empty
     if (empty($code)) {
         if (c::get('lang.detect')) {
             // detect the current language
             $detected = str::split(server::get('http_accept_language'), '-');
             $detected = str::trim(a::first($detected));
             $detected = !in_array($detected, $available) ? c::get('lang.default') : $detected;
             // set the detected code as current code
             $code = $detected;
         } else {
             $code = c::get('lang.default');
         }
         // go to the default homepage
         go(url(false, $code));
     }
     // http://yourdomain.com/error
     // will redirect to http://yourdomain.com/en/error
     if ($code == c::get('404')) {
         go(url('error', c::get('lang.default')));
     }
     // validate the code and switch back to the homepage if it is invalid
     if (!in_array($code, c::get('lang.available'))) {
         go(url());
     }
     // set the current language
     c::set('lang.current', $code);
     // mark if this is a translated version or the default version
     $code != c::get('lang.default') ? c::set('lang.translated', true) : c::set('lang.translated', false);
     // load the additional language files if available
     load::language();
 }
开发者ID:codecuts,项目名称:lanningsmith-website,代码行数:49,代码来源:site.php

示例3: bool

 /**
  * Evaluates `$X` as a boolean
  *
  * In detail:
  *
  * + If `$X` is an object, calls `$X->toBoolean()` or `$X->toBool()` if they exist.
  * + If `$X` is a countable object, returns whether `count($X) > 0`.
  *
  * @example Number to boolean
  * ```php
  * var_dump( type::bool(1)  ); // Integer
  * var_dump( type::bool(0)  ); // Zero
  * var_dump( type::bool(-1) ); // Negative
  * ```
  * @example String to boolean
  * ```php
  * var_dump( type::bool('string') ); // String
  * var_dump( type::bool('')       ); // Empty String
  * ```
  * @example Array to boolean
  * ```php
  * var_dump( type::bool(array ('A', 'B', 'C')) ); // Array
  * var_dump( type::bool(array ())              ); // Empty Array
  * ```
  * @example Semantic evaluation
  * ```php
  * // A string that is not empty, but "falsy" word is evaluated as false.
  * var_dump( type::bool('false') );
  * var_dump( type::bool('False') );
  * var_dump( type::bool('FALSE') );
  * var_dump( type::bool('null')  );
  * var_dump( type::bool('Null')  );
  * var_dump( type::bool('NULL')  );
  * var_dump( type::bool('no')    );
  * var_dump( type::bool('No')    );
  * var_dump( type::bool('NO')    );
  * var_dump( type::bool('off')   );
  * var_dump( type::bool('Off')   );
  * var_dump( type::bool('OFF')   );
  * ```
  * @example Methods evaluation
  * ```php
  * class Truthy {
  *   function toBool() {
  *     return true;
  *   }
  * }
  *
  * class Falsy {
  *   function toBool() {
  *     return false;
  *   }
  * }
  *
  * $obj1 = new Truthy();
  * $obj2 = new Falsy();
  * var_dump( type::bool($obj1) );
  * var_dump( type::bool($obj2) );
  * ```
  * @param mixed $X A variable to treat as a boolean
  * @param boolean $Alt *(optional)* An alternative value to return if evaluation has failed
  * @return boolean
  */
 static function bool($X, $Alt = false)
 {
     if (is_bool($X)) {
         return $X;
     }
     if (is_string($X)) {
         if (!$X) {
             return false;
         }
         switch (str::trim($X)) {
             case 'false':
             case 'False':
             case 'FALSE':
             case 'null':
             case 'Null':
             case 'NULL':
             case 'no':
             case 'No':
             case 'NO':
             case 'off':
             case 'Off':
             case 'OFF':
                 return false;
         }
     } else {
         if (is_object($X)) {
             if ($X instanceof \Countable) {
                 return $X->count() > 0;
             }
             $r = null;
             if (is_callable(array($X, 'toBoolean'))) {
                 $r = $X->toBoolean();
             } else {
                 if (is_callable(array($X, 'toBool'))) {
                     $r = $X->toBool();
                 }
             }
//.........这里部分代码省略.........
开发者ID:amekusa,项目名称:plz,代码行数:101,代码来源:type.php

示例4: is_visible

 /**
  * Returns whether `$X` contains any visible character
  * @example Demonstration
  * ```php
  * $var1 = " \t \n ";   // Spaces, Tab, Linebreak
  * $var2 = " \t \n _ "; // Spaces, Tab, Linebreak, and Underscore
  * var_dump( str::is_visible($var1) );
  * var_dump( str::is_visible($var2) );
  * ```
  * @param string $X
  * @return boolean
  */
 static function is_visible($X)
 {
     return !empty(str::trim($X));
 }
开发者ID:amekusa,项目名称:plz,代码行数:16,代码来源:str.php


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