[ Index ]
 

Code source de CakePHP 1.1.13.4450

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/cake/libs/ -> neat_string.php (source)

   1  <?php
   2  /* SVN FILE: $Id: neat_string.php 4409 2007-02-02 13:20:59Z phpnut $ */
   3  /**
   4   * String handling methods.
   5   *
   6   * Random passwords, splitting strings into arrays, removing Cyrillic characters, stripping whitespace.
   7   *
   8   * PHP versions 4 and 5
   9   *
  10   * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
  11   * Copyright 2005-2007, Cake Software Foundation, Inc.
  12   *            1785 E. Sahara Avenue, Suite 490-204
  13   *            Las Vegas, Nevada 89104
  14   *
  15   * Licensed under The MIT License
  16   * Redistributions of files must retain the above copyright notice.
  17   *
  18   * @filesource
  19   * @copyright        Copyright 2005-2007, Cake Software Foundation, Inc.
  20   * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  21   * @package            cake
  22   * @subpackage        cake.cake.libs
  23   * @since            CakePHP(tm) v 0.2.9
  24   * @version            $Revision: 4409 $
  25   * @modifiedby        $LastChangedBy: phpnut $
  26   * @lastmodified    $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
  27   * @license            http://www.opensource.org/licenses/mit-license.php The MIT License
  28   */
  29  /**
  30   * String handling methods.
  31   *
  32   * Random passwords, splitting strings into arrays, removing Cyrillic characters, stripping whitespace.
  33   *
  34   * @package        cake
  35   * @subpackage    cake.cake.libs
  36   */
  37  class NeatString{
  38  /**
  39   * Returns an array with each of the non-empty characters in $string as an element.
  40   *
  41   * @param string $string
  42   * @return array
  43   */
  44  	function toArray($string) {
  45          $split = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
  46          return $split;
  47      }
  48  /**
  49   * Returns string with Cyrillic characters translated to Roman ones.
  50   *
  51   * @param string $string
  52   * @return string
  53   */
  54  	function toRoman($string) {
  55          $pl = array('ą','ć','ę','ł','ń','ó','ś','ź','ż','Ą','Ć','Ę','�?','Ń','Ó','Ś','Ź','Ż');
  56          $ro = array('a','c','e','l','n','o','s','z','z','A','C','E','L','N','O','S','Z','Z');
  57          $replace = str_replace($pl, $ro, $string);
  58          return $replace;
  59      }
  60  /**
  61   * Returns string as lowercase with whitespace removed.
  62   *
  63   * @param string $string
  64   * @return string
  65   */
  66  	function toCompressed($string) {
  67          $whitespace = array("\n", "    ", "\r", "\0", "\x0B", " ");
  68          $replace = strtolower(str_replace($whitespace, '', $string));
  69          return $replace;
  70      }
  71  /**
  72   * Returns a random password.
  73   *
  74   * @param integer $length Length of generated password
  75   * @param string $available_chars List of characters to use in password
  76   * @return string Generated password
  77   */
  78  	function randomPassword($length, $available_chars = 'ABDEFHKMNPRTWXYABDEFHKMNPRTWXY23456789') {
  79          $chars = preg_split('//', $available_chars, -1, PREG_SPLIT_NO_EMPTY);
  80          $char_count = count($chars);
  81          $out = '';
  82          for($ii = 0; $ii < $length; $ii++) {
  83              $out .= $chars[rand(1, $char_count)-1];
  84          }
  85          return $out;
  86      }
  87  }
  88  ?>


Généré le : Sun Feb 25 19:27:47 2007 par Balluche grâce à PHPXref 0.7