字符处理对象
API - Core_Text
- Text::$units
- Text::limit_words - Limits a phrase to a given number of words.
- Text::limit_chars - Limits a phrase to a given number of characters.
- Text::alternate - Alternates between two or more strings.
- Text::random - Generates a random string of a given type and length.
- Text::reduce_slashes - Reduces multiple slashes in a string to single slashes.
- Text::censor - Replaces the given words with a string.
- Text::similar - Finds the text that is similar between a set of words.
- Text::auto_link - Converts text email addresses and anchors into links. Existing links
- Text::auto_link_urls - Converts text anchors into links. Existing links will not be altered.
- Text::auto_link_emails - Converts text email addresses into links. Existing links will not
- Text::auto_p - Automatically applies "p" and "br" markup to text.
- Text::bytes - Returns human readable sizes. Based on original functions written by
- Text::number - Format a number to human-readable text.
- Text::widont - Prevents [widow words](http://www.shauninman.com/archive/2006/08/22/widont_wordpress_plugin)
- Text::escape - 等同js脚本里的escape函数
- Text::unescape - 等同js脚本里的unescape函数
- Text::substr - 截取文件
- Text::rc4_encrypt - 使用rc4优化版加密字符串
- Text::rc4_decryption - 解密使用rc4优化版加密的字符串
Limits a phrase to a given number of words.
$text = Text::limit_words($text);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Phrase to limit words of | |
$limit |
integer |
Number of words to limit to | integer 100 |
$end_char |
string |
End character or entity | null |
string
Limits a phrase to a given number of characters.
$text = Text::limit_chars($text);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Phrase to limit characters of | |
$limit |
integer |
Number of characters to limit to | integer 100 |
$end_char |
string |
End character or entity | null |
$preserve_words |
boolean |
Enable or disable the preservation of words while limiting | bool false |
string
Alternates between two or more strings.
echo Text::alternate('one', 'two'); // "one" echo Text::alternate('one', 'two'); // "two" echo Text::alternate('one', 'two'); // "one"
Note that using multiple iterations of different strings may produce unexpected results.
string
Generates a random string of a given type and length.
$str = Text::random(); // 8 character random string
The following types are supported:
You can also create a custom type by providing the "pool" of characters as the type.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$type |
string |
A type of pool, or a string of characters to use as the pool | null |
$length |
integer |
Length of string to return | integer 8 |
string
Reduces multiple slashes in a string to single slashes.
$str = Text::reduce_slashes('foo//bar/baz'); // "foo/bar/baz"
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
String to reduce slashes of |
string
Replaces the given words with a string.
// Displays "What the #####, man!" echo Text::censor('What the frick, man!', array( 'frick' => '#####', ));
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Phrase to replace words in | |
$badwords |
array |
Words to replace | |
$replacement |
string |
Replacement string | string(1) "#" |
$replace_partial_words |
boolean |
Replace words across word boundries (space, period, etc) | bool true |
string
Finds the text that is similar between a set of words.
$match = Text::similar(array('fred', 'fran', 'free'); // "fr"
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$words |
array |
Words to find similar text of |
string
Converts text email addresses and anchors into links. Existing links will not be altered.
echo Text::auto_link($text);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$text |
string |
Text to auto link |
string
Converts text anchors into links. Existing links will not be altered.
echo Text::auto_link_urls($text);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$text |
string |
Text to auto link |
string
Converts text email addresses into links. Existing links will not be altered.
echo Text::auto_link_emails($text);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$text |
string |
Text to auto link |
string
Automatically applies "p" and "br" markup to text. Basically nl2br on steroids.
echo Text::auto_p($text);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Subject | |
$br |
boolean |
Convert single linebreaks to |
bool true |
string
Returns human readable sizes. Based on original functions written by Aidan Lister and Quentin Zervaas.
echo Text::bytes(filesize($file));
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$bytes |
integer |
Size in bytes | |
$force_unit |
string |
A definitive unit | null |
$format |
string |
The return string format | null |
$si |
boolean |
Whether to use SI prefixes or IEC | bool true |
string
Format a number to human-readable text.
// Display: one thousand and twenty-four echo Text::number(1024);
// Display: five million, six hundred and thirty-two echo Text::number(5000632);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$number |
integer |
Number to format |
string
Prevents widow words by inserting a non-breaking space between the last two words.
echo Text::widont($text);
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Text to remove widows from |
string
等同js脚本里的escape函数
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
$str | |
$encode |
string |
$encode | string(5) "UTF-8" |
等同js脚本里的unescape函数
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
$str | |
$encode |
string |
$encode | string(5) "UTF-8" |
截取文件
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
$str | |
$start |
int |
$start | |
$length |
int |
$length | null |
$encoding |
string |
$encoding | string(5) "UTF-8" |
使用rc4优化版加密字符串
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$string |
string |
$string | |
$key |
string |
不传或null则用默认值 | null |
$expiry |
int |
设置有效期 | integer 0 |
解密使用rc4优化版加密的字符串
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$string |
string |
$string | |
$key |
unknown |
null |
优化版rc4加密解密
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$string |
string |
$string | |
$is_decode |
string |
$is_decode | bool true |
$key |
string |
$key | null |
$expiry |
number |
$expiry | integer 0 |
string