选择语言 :

Core_Text

字符处理对象

API - Core_Text

author
呼吸二氧化碳 jonwang@myqee.com
category
MyQEE
package
System
subpackage
Core
copyright
Copyright © 2008-2013 myqee.com
license
http://www.myqee.com/license.html

Text::limit_words( $str , $limit = 100, $end_char = null)

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

Text::limit_chars( $str , $limit = 100, $end_char = null, $preserve_words = false)

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

Text::alternate( )

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

Text::random( $type = null, $length = 8)

Generates a random string of a given type and length.

$str = Text::random(); // 8 character random string

The following types are supported:

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

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

Text::reduce_slashes( $str )

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

Text::censor( $str , $badwords , $replacement = '#', $replace_partial_words = true)

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

Text::similar( $words )

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

Text::auto_link( $text )

Converts text email addresses and anchors into links. Existing links will not be altered.

echo Text::auto_link($text);

This method is not foolproof since it uses regex to parse HTML.

参数列表

参数 类型 描述 默认值
$text string Text to auto link
返回值
  • string

Text::auto_link_urls( $text )

Converts text anchors into links. Existing links will not be altered.

echo Text::auto_link_urls($text);

This method is not foolproof since it uses regex to parse HTML.

参数列表

参数 类型 描述 默认值
$text string Text to auto link
返回值
  • string

Text::_auto_link_urls_callback1( )


Text::_auto_link_urls_callback2( )


Text::auto_link_emails( $text )

Converts text email addresses into links. Existing links will not be altered.

echo Text::auto_link_emails($text);

This method is not foolproof since it uses regex to parse HTML.

参数列表

参数 类型 描述 默认值
$text string Text to auto link
返回值
  • string

Text::_auto_link_emails_callback( )


Text::auto_p( $str , $br = true)

Automatically applies "p" and "br" markup to text. Basically nl2br on steroids.

echo Text::auto_p($text);

This method is not foolproof since it uses regex to parse HTML.

参数列表

参数 类型 描述 默认值
$str string Subject
$br boolean Convert single linebreaks to
bool true
返回值
  • string

Text::bytes( $bytes , $force_unit = null, $format = null, $si = true)

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

Text::number( $number )

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

Text::widont( $str )

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

Text::escape( $str , $encode = 'UTF-8')

等同js脚本里的escape函数

参数列表

参数 类型 描述 默认值
$str string $str
$encode string $encode string(5) "UTF-8"

Text::unescape( $str , $encode = 'UTF-8')

等同js脚本里的unescape函数

参数列表

参数 类型 描述 默认值
$str string $str
$encode string $encode string(5) "UTF-8"

Text::substr( $str , $start , $length = null, $encoding = 'UTF-8')

截取文件

参数列表

参数 类型 描述 默认值
$str string $str
$start int $start
$length int $length null
$encoding string $encoding string(5) "UTF-8"

Text::rc4_encrypt( $string , $key = null, $expiry = 0)

使用rc4优化版加密字符串

参数列表

参数 类型 描述 默认值
$string string $string
$key string 不传或null则用默认值 null
$expiry int 设置有效期 integer 0

Text::rc4_decryption( $string , $key = null)

解密使用rc4优化版加密的字符串

参数列表

参数 类型 描述 默认值
$string string $string
$key unknown null

Text::rc4( $string , $is_decode = true, $key = null, $expiry = 0)

优化版rc4加密解密

参数列表

参数 类型 描述 默认值
$string string $string
$is_decode string $is_decode bool true
$key string $key null
$expiry number $expiry integer 0
返回值
  • string