>> YANA 4 PHP Framework >> Docs For Class String_type

Class String_type

Description

«datatype» String_type

This is a OO-wrapper for the scalar string type of PHP. This implementation is compatible with PHP 4 and 5.

Note: this class is still under developement. Use as see fit but be aware of possible changes in the future.

  • name: string_type
  • access: public

Located in /includes/class_string_type.php


	
			

Method Summary

String_type String_type (mixed $value, string $stringValue )
string &addSlashes ([string $charlist = ""])
void charAt (int $index)
int(+1)|int(0)|int(-1) compareTo (string $anotherString)
int(+1)|int(0)|int(-1) compareToIgnoreCase (string $anotherString)
string &decode (string $encoding, [int $style = ENT_COMPAT], [string $charset = ""])
string encode (string $encoding, [string $style = ENT_COMPAT], [string $charset = ""])
string &encrypt ([string $encryption = "md5"], [string $salt = ""])
boolean equals (mixed $something)
string get ()
string htmlEntities (string $input)
int indexOf (string $needle, int $offset)
int length ()
array|bool(false) match (string $regularExpression)
array|bool(false) matchAll (string $regularExpression)
string &removeSlashes (string $charlist)
int replace (string $needle, [string $substitute = ""])
int replaceRegExp (mixed $regularExpression, [string $substitute = ""], [int $limit = -1], string $needle)
string &reverse ()
string set (mixed $value, string $new_value)
string &shuffle ()
array split (string $separator, int $limit)
array splitRegExp (string $separator, int $limit)
string &substring (int $start, int $length)
bool toBool ()
float|bool(false) toFloat ()
int|bool(false) toInt ()
string &toLowerCase ()
void toString ()
string &toUpperCase ()
string &trim ()
string &wrap (int $width, [string $break = ""], [bool $cut = false])

Methods

Constructor String_type
String_type String_type (mixed $value, string $stringValue )

create new instance

Creates a new string wrapper. The input must be convertable to a string value.

  • name: string_type::__construct()
Name Type Description
$stringValue string
addSlashes
string &addSlashes ([string $charlist = ""])

OO-Alias of: addslashes(), addcslashes()

  • name: string_type::addslashes()
  • access: public
Name Type Description
$charlist string (optional)
charAt
void charAt (int $index)

OO-Alias of: $string[$index]

Returns bool(false) on error. Issues an E_USER_ERROR if $index is of wrong type. Issues an E_USER_NOTICE if $index is out of bounds.

Note that indices are numbered starting with '0'.

  • name: string_type::charat()
  • access: public
Name Type Description
$index int (optional)
compareTo
int(+1)|int(0)|int(-1) compareTo (string $anotherString)

compare two strings

Returns

  • int(-1) if this string < $anotherString
  • int(+0) if this string === $anotherString
  • int(+1) if this string > $anotherString

Note: This function is case-sensitive.

  • see: string_type::comparetoignorecase()
  • name: string_type::compareto()
  • access: public
Name Type Description
$anotherString string
compareToIgnoreCase
int(+1)|int(0)|int(-1) compareToIgnoreCase (string $anotherString)

compare two strings (ignore case)

Returns

  • int(-1) if this string < $anotherString
  • int(+0) if this string === $anotherString
  • int(+1) if this string > $anotherString

Note: This function is NOT case-sensitive.

  • see: string_type::compareto()
  • name: string_type::comparetoignorecase()
  • access: public
Name Type Description
$anotherString string
copy
String_type copy ()

copy / clone the string

creates a copy of this object

  • name: string_type::copy()
  • access: public
decode
string &decode (string $encoding, [int $style = ENT_COMPAT], [string $charset = ""])

decode a string (revertable)

Note: charset applies only to encoding = "entities"

This function is the opposite of "encode()". See "encode()" for details on the available types of encoding.

  • see: string_type::encode()
  • see: string_type::encrypt()
  • name: string_type::decode()
  • access: public
Name Type Description
$encoding string
$style int (optional)
$charset string (optional)
encode
string encode (string $encoding, [string $style = ENT_COMPAT], [string $charset = ""])

encode a string (revertable)

Note: charset applies only to encoding = "entities"

Returns an encoded version depending on the type of encoding you choose.

The input value is not case-sensitive.

Note: The results of this function can be reversed using the "decode()" function with the same values. If you are looking for checksums and hashing-methods see the "encrypt" function.

The following values are available.

  • unicode: uses utf8_encode(), aliases: "utf", "utf8"
  • base64: uses base64_encode()
  • url: uses urlencode()
  • rawurl: uses rawurlencode()
  • entities: uses htmlentities(), uses $style argument
  • rot13: does a ROT13 transformation
  • quote: quotes meta signs using quotemeta()
  • regexp: uses preg_quote(), alias: "regular expression"

  • see: string_type::decode()
  • see: string_type::encrypt()
  • name: string_type::encode()
  • access: public
Name Type Description
$encoding string see the list of valid inputs for details
$style string (optional)
$charset string (optional)
encrypt
string &encrypt ([string $encryption = "md5"], [string $salt = ""])

encrypt or transform a string (not revertable)

Returns an encrypted version depending on the type of encryption you choose.

The input value is not case-sensitive.

Note: The result of this function is alwas irreversible. If you are looking for reversible encryption methods see the "encode" function.

The following values are available.

  • crc32: computes the crc32 checksum value of the string
  • md5: computes the md5 hash-string
  • sha1: computes the sha1 hash-string
  • crypt: uses crypt() function, result depending on $salt. See PHP-Manual for details.
  • des: uses DES encryption algorithm
  • blowfish: uses BLOWFISH encryption algorithm
  • soundex: calculates the soundex hash: While this is not an encryption algorithm, it is listed here, because it is uses some sort of irreversible hashing and thus won't fit to encoding()
  • metaphone:calculates the metaphone hash: While this is not an encryption algorithm, it is listed here, for the same reason as "soundex". Note: uses the argument $salt as second argument for metaphone() if $salt is a numeric value, that can be converted to int.

  • see: string_type::encode()
  • name: string_type::encrypt()
  • access: public
Name Type Description
$encryption string (optional) see the list of valid inputs for details
$salt string (optional) only used for certain encryption types
equals
boolean equals (mixed $something)

test two strings for equality

Returns

  • bool(true) if and only if this string === $something
  • bool(false) on every other case

Note: this is unlike the PHP code ($string == $something) where you might accidently run into comparision in e.g. a boolean context.

  • name: string_type::equals()
  • access: public
Name Type Description
$something mixed
get
string get ()

get string value

Unboxing the object. This function returns the scalar string value of the object.

  • name: string_type::get()
  • access: public
htmlEntities
string htmlEntities (string $input)

convert to html entities

  • see: string_type::encode()
  • name: string_type::htmlentities()
  • static:
  • access: public
Name Type Description
$input string
indexOf
int indexOf (string $needle, int $offset)

get position of first occurence of a needle inside the string

Returns character-offset of first occurence of $needle within this string. Indices starting with int(0).

Returns Java-style int(-1) if $needle is not found, NOT Php-style bool(false). This is because int(0) and bool(false) might get mixed by accident.

So while if

  1. (strpos($string, $needle) == 0))
will return true, even if $needle is not found, the test
  1. if ($string->indexOf($needle) == 0)
will return false if $needle is not found and true if and only if $string starts with the string $needle.

  • name: string_type::indexof()
  • access: public
Name Type Description
$needle string
$offset int (optional)
length
int length ()

get the length of the string

  • name: string_type::length()
  • access: public
match
array|bool(false) match (string $regularExpression)

match string against regular expression

Matches this string against a given Perl-compatible regular expression. Returns an array containing the FIRST set of matches or bool(false) if the regular expression did not match at all.

  • see: string_type::matchall()
  • name: string_type::match()
  • access: public
Name Type Description
$regularExpression string
matchAll
array|bool(false) matchAll (string $regularExpression)

match string against regular expression (return all results)

Matches this string against a given Perl-compatible regular expression. Returns an array containing ALL the matches or bool(false) if the regular expression did not match at all.

  • see: string_type::match()
  • name: string_type::matchall()
  • access: public
Name Type Description
$regularExpression string
removeSlashes
string &removeSlashes (string $charlist)

OO-Alias of: stripslashes(), stripcslashes()

  • name: string_type::removeslashes()
  • access: public
Name Type Description
$charlist string (optional)
replace
int replace (string $needle, [string $substitute = ""])

replace a needle with a substitute

  • return: number of times $needle is replaced
  • see: string_type::replaceregexp()
  • name: string_type::replace()
  • access: public
Name Type Description
$needle string
$substitute string (optional)
replaceRegExp
int replaceRegExp (mixed $regularExpression, [string $substitute = ""], [int $limit = -1], string $needle)

replace a substring by using a regular expression

  • return: number of times $needle is replaced
  • see: string_type::replace()
  • name: string_type::replaceregexp()
  • access: public
Name Type Description
$needle string
$substitute string (optional)
$limit int (optional) must be a positive integer > 0, defaults to -1 (no limit)
reverse
string &reverse ()

reverse the string value

  • name: string_type::reverse()
  • access: public
set
string set (mixed $value, string $new_value)

set string value

Assigns a new value to the object. Returns the old value.

  • name: string_type::set()
  • access: public
Name Type Description
$new_value string
shuffle
string &shuffle ()

shuffle the string's characters

  • name: string_type::shuffle()
  • access: public
split
array split (string $separator, int $limit)

convert string to an array

  • see: string_type::splitregexp()
  • name: string_type::split()
  • access: public
Name Type Description
$separator string
$limit int (optional)
splitRegExp
array splitRegExp (string $separator, int $limit)

convert string to an array by using regular expression to find a speratator

  • see: string_type::split()
  • name: string_type::splitregexp()
  • access: public
Name Type Description
$separator string
$limit int (optional)
substring
string &substring (int $start, int $length)

extract a substring

Returns a substring beginning at character-offset $start with $length characters. See PHP-Manual "string functions" "substr()" for details.

  • name: string_type::substring()
  • access: public
Name Type Description
$start int
$length int (optional)
toBool
bool toBool ()

return value as boolean

Returns a boolean value depending on the value of the string.

  • string("false") returns bool(false)
  • string("true") returns bool(true)
  • any other value returns a boolean value depending on the result of PHP's internal conversion mechanism, BUT also issues an E_USER_NOTICE for on an invalid string to bool conversion

Note: If you just want to check wether a string is empty or not, use $string->equals("") instead.

  • name: string_type::tobool()
  • access: public
toFloat
float|bool(false) toFloat ()

return value as float

Converts the string value to a float and returns it. Returns bool(false) if the string is not numeric.

  • name: string_type::tofloat()
  • access: public
toInt
int|bool(false) toInt ()

return value as int

Converts the string value to an integer and returns it. Returns bool(false) if the string is not numeric.

  • name: string_type::toint()
  • access: public
toLowerCase
string &toLowerCase ()

return a lower-cased version of the string

  • see: string_type::touppercase()
  • name: string_type::tolowercase()
  • access: public
toString
void toString ()

Alias of: String_type::get()

  • see: string_type::get()
toUpperCase
string &toUpperCase ()

return a upper-cased version of the string

  • see: string_type::tolowercase()
  • name: string_type::touppercase()
  • access: public
trim
string &trim ()

OO-Alias of: trim(), chop()

  • name: string_type::trim()
  • access: public
wrap
string &wrap (int $width, [string $break = ""], [bool $cut = false])

wrap a long text

Note: THIS FUNCTION IS NOT BINARY-SAFE!

  • name: string_type::wrap()
  • access: public
Name Type Description
$width int (optional)
$break string (optional)
$cut bool (optional)

Documentation generated on Sat, 16 Sep 2006 17:06:06 +0200 by phpDocumentor 1.3.0RC4

yana author: Thomas MeyerHomepage: www.all-community.de/pub