PHP Class Habari\MultiByte

Provides multibyte character set services, a necessity since all of Habari's internal string manipulations are done in UTF-8. Currently this class is a wrapper around mbstring functions.
Show file Open project: habari/system

Public Properties

Property Type Description
$hab_enc String holding the current encoding the class is using

Public Methods

Method Description
convert_encoding ( $str, $use_enc = null, $from_enc = null ) : mixed Converts a string's encoding to a new encoding
detect_bom_encoding ( $source_contents ) : mixed Detects the encoding being used for a string using the existence of a byte order mark
detect_encoding ( $str ) : mixed Detects the encoding being used for a string
hab_encoding ( $use_enc = null ) : string. Sets and returns the internal encoding.
lcfirst ( string $str, string $use_enc = null ) : string Makes a string's first character lowercase
library ( integer $new_library = null ) : mixed Sets and returns the multibyte library being used internally
str_ireplace ( mixed $search, mixed $replace, string $subject, integer &$count, string $use_enc = null ) : string Replace all occurrences of the search string with the replacement string.
str_replace ( mixed $search, mixed $replace, string $subject, integer &$count, string $use_enc = null ) : string Replace all occurrences of the search string with the replacement string.
stripos ( $haysack, $needle, $offset, $use_enc = null ) : mixed Find position of first occurrence of string in a string. Case insensitive.
strlen ( $str, $use_enc = null ) : integer. Gets the length of a string in characters
strpos ( $haysack, $needle, $offset, $use_enc = null ) : mixed Find position of first occurrence of string in a string
strripos ( $haysack, $needle, $offset, $use_enc = null ) : mixed Find position of last occurrence of string in a string. Case insensitive.
strrpos ( $haysack, $needle, $offset, $use_enc = null ) : mixed function strrpos
strtolower ( $str, $use_enc = null ) : string. function strtolower
strtoupper ( $str, $use_enc = null ) : string. Converts a multibyte string to uppercase. If a valid multibyte library isn't loaded, strtoupper() will be used, which can lead to unexpected results.
substr ( $str, $begin, $len = null, $use_enc = null ) : mixed Get a section of a string
ucfirst ( string $str, string $use_enc = null ) : string Makes a string's first character uppercase
ucwords ( string $str, string $use_enc = null ) : string Uppercase the first character of each word in a string.
valid_data ( string $str, null $use_enc = null ) : boolean Determines if the passed string is valid character data (according to mbstring)

Private Methods

Method Description
__construct ( ) An empty constructor since all functions are static

Method Details

convert_encoding() public static method

Converts a string's encoding to a new encoding
public static convert_encoding ( $str, $use_enc = null, $from_enc = null ) : mixed
$str string. The string who's encoding is being changed.
$use_enc string. The encoding to convert to. If not set, the internal encoding will be used.
$from_enc string. encoding before conversion. If not set, encoding is detected automatically.
return mixed The source string in the new encoding or boolean false.

detect_bom_encoding() public static method

Detects the encoding being used for a string using the existence of a byte order mark
public static detect_bom_encoding ( $source_contents ) : mixed
$source_contents string. The string whose encoding is being detected
return mixed The source string's detected encoding, or boolean false.

detect_encoding() public static method

Detects the encoding being used for a string
public static detect_encoding ( $str ) : mixed
$str string. The string whose encoding is being detected
return mixed The source string's detected encoding, or boolean false.

hab_encoding() public static method

Sets and returns the internal encoding.
public static hab_encoding ( $use_enc = null ) : string.
$use_enc string. The encoding to be used
return string.

lcfirst() public static method

Makes a string's first character lowercase
See also: http://php.net/ucfirst
public static lcfirst ( string $str, string $use_enc = null ) : string
$str string The string to lowercase.
$use_enc string The encoding to be used. If null, the internal encoding will be used.
return string The lowercased string.

library() public static method

Sets and returns the multibyte library being used internally
public static library ( integer $new_library = null ) : mixed
$new_library integer The new library to use. One of the self::USE_* constants, null to simply return, or false to disable and use native non-multibyte-safe PHP methods.
return mixed If $new_library is null, returns the current library being used. If $new_library has a valid value, returns the old library, else returns false.

str_ireplace() public static method

Replace all occurrences of the search string with the replacement string.
See also: http://php.net/str_ireplace
public static str_ireplace ( mixed $search, mixed $replace, string $subject, integer &$count, string $use_enc = null ) : string
$search mixed A string or an array of strings to search for.
$replace mixed A string or an array of strings to replace search values with.
$subject string The string to perform the search and replace on.
$count integer If passed, this value will hold the number of matched and replaced needles.
$use_enc string The encoding to be used. If null, the internal encoding will be used.
return string The subject with replaced values.

str_replace() public static method

Replace all occurrences of the search string with the replacement string.
See also: http://php.net/str_replace
public static str_replace ( mixed $search, mixed $replace, string $subject, integer &$count, string $use_enc = null ) : string
$search mixed A string or an array of strings to search for.
$replace mixed A string or an array of strings to replace search values with.
$subject string The string to perform the search and replace on.
$count integer If passed, this value will hold the number of matched and replaced needles.
$use_enc string The encoding to be used. If null, the internal encoding will be used.
return string The subject with replaced values.

stripos() public static method

Find position of first occurrence of string in a string. Case insensitive.
public static stripos ( $haysack, $needle, $offset, $use_enc = null ) : mixed
$haysack string. The string being checked.
$offset integer. The search offset. If it is not specified, 0 is used.
$use_enc string. The encoding to be used. If not set, the internal encoding will be used.
return mixed The section of the source string requested in the encoding requested or false. If $len is not set, returns substring from $begin to end of string.

strlen() public static method

Gets the length of a string in characters
public static strlen ( $str, $use_enc = null ) : integer.
$str string. The string who's length is being returned.
$use_enc string. The encoding to be used. If not set, the internal encoding will be used.
return integer.

strpos() public static method

Find position of first occurrence of string in a string
public static strpos ( $haysack, $needle, $offset, $use_enc = null ) : mixed
$haysack string. The string being checked.
$offset integer. The search offset. If it is not specified, 0 is used.
$use_enc string. The encoding to be used. If not set, the internal encoding will be used.
return mixed The section of the source string requested in the encoding requested or false. If $len is not set, returns substring from $begin to end of string.

strripos() public static method

Find position of last occurrence of string in a string. Case insensitive.
public static strripos ( $haysack, $needle, $offset, $use_enc = null ) : mixed
$haysack string. The string being checked.
$offset integer. The search offset. If it is not specified, 0 is used.
$use_enc string. The encoding to be used. If not set, the internal encoding will be used.
return mixed The section of the source string requested in the encoding requested or false. If $len is not set, returns substring from $begin to end of string.

strrpos() public static method

Find position of last occurrence of string in a string.
public static strrpos ( $haysack, $needle, $offset, $use_enc = null ) : mixed
$haysack string. The string being checked.
$offset integer. The search offset. If it is not specified, 0 is used.
$use_enc string. The encoding to be used. If not set, the internal encoding will be used.
return mixed The section of the source string requested in the encoding requested or false. If $len is not set, returns substring from $begin to end of string.

strtolower() public static method

Converts a multibyte string to lowercase. If a valid multibyte library isn't loaded, strtolower() will be used, which can lead to unexpected results.
public static strtolower ( $str, $use_enc = null ) : string.
$str string. The string to lowercase
$use_enc string. The encoding to be used. If not set, the internal encoding will be used.
return string.

strtoupper() public static method

Converts a multibyte string to uppercase. If a valid multibyte library isn't loaded, strtoupper() will be used, which can lead to unexpected results.
public static strtoupper ( $str, $use_enc = null ) : string.
$str string. The string to uppercase
$use_enc string. The encoding to be used. If not set, the internal encoding will be used.
return string.

substr() public static method

Get a section of a string
public static substr ( $str, $begin, $len = null, $use_enc = null ) : mixed
$str string. The original string
$len integer. How long the returned string should be. If $len is not set, the section of the string from $begin to the end of the string is returned.
$use_enc string. The encoding to be used. If not set, the internal encoding will be used.
return mixed The section of the source string requested in the encoding requested or false. If $len is not set, returns substring from $begin to end of string.

ucfirst() public static method

Makes a string's first character uppercase
See also: http://php.net/ucfirst
public static ucfirst ( string $str, string $use_enc = null ) : string
$str string The string to capitalize.
$use_enc string The encoding to be used. If null, the internal encoding will be used.
return string The capitalized string.

ucwords() public static method

From php.net/ucwords: The definition of a word is any string of characters that is immediately after a whitespace (These are: space, form-feed, newline, carriage return, horizontal tab, and vertical tab).
See also: http://php.net/ucwords
public static ucwords ( string $str, string $use_enc = null ) : string
$str string The input string.
$use_enc string The encoding to be used. If null, the internal encoding will be used.
return string The modified string.

valid_data() public static method

Determines if the passed string is valid character data (according to mbstring)
public static valid_data ( string $str, null $use_enc = null ) : boolean
$str string the string to check
$use_enc null
return boolean

Property Details

$hab_enc static public property

String holding the current encoding the class is using
static public $hab_enc