Cakephp2.0 String 类

String 处理字符串

1 String::uuid()

$rs = String::uuid();

$pattern = "/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/";

(bool) preg_match($pattern, $rs) == true;

产生一个这样格式的的随机数字abcd1234-ab12-ab12-ab12-adcdef123456

 

2.String::insert() 将字符串按照一定规则替换成相应的字符

$string = '2 + 2 = :sum. Cake is :adjective.';

$result = String::insert($string, array('sum' => '4', 'adjective' => 'yummy'));

$result == '2 + 2 = 4. Cake is yummy.';

第三个参数可以是

array('before' => '<','after' => '>')

array('format'=> '/([\d])%s\\1/')

array('escape' => '!')

array('clean' => true)

array('clean' => 'html')

......

3 String::tokenize 将字符串分割成数组

String::tokenize('A,(short,boring test)') == array('A', '(short,boring test)');

 

4 String::wrap

String::wrap('This is the song that never ends. This is the song that never ends. This is the song that never ends.',33) == <<<TEXT
This is the song that never ends.
This is the song that never ends.
This is the song that never ends.
TEXT;

 

5 String::cleanInsert 按照规则将字符串中的字符清除掉

String::cleanInsert(':incomplete', array(
   'clean' => true, 'before' => ':', 'after' => ''
  )) == '';

你可能感兴趣的:(类,String,Cakephp2.0)