Kohana之Text

这个类有常用的字符串操作

轮流输出指定数组内的值

<?php
echo Text::alternate('one', 'two'); 
echo Text::alternate('one', 'two'); 
echo Text::alternate('one', 'two'); 

自动给文本中的邮箱地址加链接

<?php
echo Text::auto_link("fasd afsd@fasd.com dfa");
echo Text::auto_link_emails("fasd afsd@fasd.com dfa");
 
加个P标签(没意义)
<?php
echo Text::auto_p("dddd");//<p>dddd</p>

 

 

转换为KB

<?php
echo Text::bytes(100000);//100.00kb


替换指定字符串

 

<?php
echo Text::censor('What the frick, man!', array(    'frick' => '#####',));


防止连续字母提交

<?php
$text = Text::limit_chars($text,100);//字
$text = Text::limit_words($text);//词

 

取得随机字符串(最有用啦~这个~)

<?php
$type=”alnum”;
$str = Text::random($type); // 8 character random string
 
$type有以下类型:

alnum
Upper and lower case a-z, 0-9
alpha
Upper and lower case a-z
hexdec
Hexadecimal characters a-f, 0-9
distinct
Uppercase characters and numbers that cannot be confused
 

修正路径
<?php
$str = Text::reduce_slashes('foo//bar/baz'); // "foo/bar/baz"
 
取得数组中相同部分
<?php
$match = Text::similar(array('fred', 'fran', 'free'); // "fr"

最后一个没什么用的~自己研究~
<?php
echo Text::widont($text);



 

 


posted @ 2010-08-19 17:01  liushan  阅读(241)  评论(0)    收藏  举报