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

Class String_type

Description

«datatype» String_type

This is an 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. You may use it already, but you should be aware of possible changes in the future.

  • name: string_type
  • access: public

Located in /includes/class_string_type.php

SerializeableObject
   |
   --String_type
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_type copy ()
  • 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

create new instance
String_type String_type (
mixed $value, string $stringValue
)
List of parameters:
Name Type Description
$stringValue string
Description:

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

  • name: string_type::__construct()
OO-Alias of: addslashes(), addcslashes()
string &addSlashes (
[string $charlist = ""]
)
List of parameters:
Name Type Description
$charlist string (optional)
Description:
  • name: string_type::addslashes()
  • access: public
OO-Alias of: $string[$index]
void charAt (
int $index
)
List of parameters:
Name Type Description
$index int (optional)
Description:

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
compare two strings
int(+1)|int(0)|int(-1) compareTo (
string $anotherString
)
List of parameters:
Name Type Description
$anotherString string
Description:

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
compare two strings (ignore case)
int(+1)|int(0)|int(-1) compareToIgnoreCase (
string $anotherString
)
List of parameters:
Name Type Description
$anotherString string
Description:

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
copy / clone the string
String_type copy ()
Description:

creates a copy of this object

  • name: string_type::copy()
  • access: public

Redefinition of: SerializeableObject::copy()

decode a string (revertable)
string &decode (
string $encoding, [int $style = ENT_COMPAT], [string $charset = ""]
)
List of parameters:
Name Type Description
$encoding string
$style int (optional)
$charset string (optional)
Description:

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
encoding, or converting a string (revertable)
string encode (
string $encoding, [string $style = ENT_COMPAT], [string $charset = ""]
)
List of parameters:
Name Type Description
$encoding string see the list of valid inputs for details
$style string (optional)
$charset string (optional)
Description:

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
hashing function, encryption, transformation (not revertable)
string &encrypt (
[string $encryption = "md5"], [string $salt = ""]
)
List of parameters:
Name Type Description
$encryption string (optional) see the list of valid inputs for details
$salt string (optional) only used for certain encryption types
Description:

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 (128Bit)
  • sha1: computes the sha1 hash-string (160Bit)
  • 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.
  • any of the encryption types supported by the PHP "hash()" function introduced as of PHP 5.1.2
  • xor: XOR is a simple revertable block chiffre. Use $salt string as password to encrypt the clear text. Call encrypt() with the same arguments again to revert the ciphered text back to clear text. Note that the security of XOR and all other simple block chiffres depend on the length and security off your password. To be really secure your password needs to be minimum as long as the clear text, which is not always praticable.

This method issues an E_USER_NOTICE and returns the integer constant STRING_UNSUPPORTED_ENCRYPTION if the $encryption parameter has an invalid value.

  • see: string_type::encode()
  • name: string_type::encrypt()
  • access: public
test two strings for equality
boolean equals (
mixed $something
)
List of parameters:
Name Type Description
$something mixed
Description:

Returns

  • bool(true) if and only if the input is of type string and string representation of the value of this object and the input string are the same, or the input is an object of the same type and the string values of both are equal
  • bool(false) otherwise

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

Redefinition of: SerializeableObject::equals()

get string value
string get ()
Description:

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

  • name: string_type::get()
  • access: public
convert to html entities
string htmlEntities (
string $input
)
List of parameters:
Name Type Description
$input string
Description:
  • see: string_type::encode()
  • name: string_type::htmlentities()
  • static:
  • access: public
get position of first occurence of a needle inside the string
int indexOf (
string $needle, int $offset
)
List of parameters:
Name Type Description
$needle string
$offset int (optional)
Description:

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
get the length of the string
int length ()
Description:
  • name: string_type::length()
  • access: public
match string against regular expression
array|bool(false) match (
string $regularExpression
)
List of parameters:
Name Type Description
$regularExpression string
Description:

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
match string against regular expression (return all results)
array|bool(false) matchAll (
string $regularExpression
)
List of parameters:
Name Type Description
$regularExpression string
Description:

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
OO-Alias of: stripslashes(), stripcslashes()
string &removeSlashes (
string $charlist
)
List of parameters:
Name Type Description
$charlist string (optional)
Description:
  • name: string_type::removeslashes()
  • access: public
replace a needle with a substitute
int replace (
string $needle, [string $substitute = ""]
)
List of parameters:
Name Type Description
$needle string
$substitute string (optional)
Description:
  • return: number of times $needle is replaced
  • see: string_type::replaceregexp()
  • name: string_type::replace()
  • access: public
replace a substring by using a regular expression
int replaceRegExp (
mixed $regularExpression, [string $substitute = ""], [int $limit = -1], string $needle
)
List of parameters:
Name Type Description
$needle string
$substitute string (optional)
$limit int (optional) must be a positive integer > 0, defaults to -1 (no limit)
Description:
  • return: number of times $needle is replaced
  • see: string_type::replace()
  • name: string_type::replaceregexp()
  • access: public
reverse the string value
string &reverse ()
Description:
  • name: string_type::reverse()
  • access: public
set string value
string set (
mixed $value, string $new_value
)
List of parameters:
Name Type Description
$new_value string
Description:

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

  • name: string_type::set()
  • access: public
shuffle the string's characters
string &shuffle ()
Description:
  • name: string_type::shuffle()
  • access: public
convert string to an array
array split (
string $separator, int $limit
)
List of parameters:
Name Type Description
$separator string
$limit int (optional)
Description:
  • see: string_type::splitregexp()
  • name: string_type::split()
  • access: public
convert string to an array by using regular expression to find a speratator
array splitRegExp (
string $separator, int $limit
)
List of parameters:
Name Type Description
$separator string
$limit int (optional)
Description:
  • see: string_type::split()
  • name: string_type::splitregexp()
  • access: public
extract a substring
string &substring (
int $start, int $length
)
List of parameters:
Name Type Description
$start int
$length int (optional)
Description:

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
return value as boolean
bool toBool ()
Description:

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
return value as float
float|bool(false) toFloat ()
Description:

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
return value as int
int|bool(false) toInt ()
Description:

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
return a lower-cased version of the string
string &toLowerCase ()
Description:
  • see: string_type::touppercase()
  • name: string_type::tolowercase()
  • access: public
Alias of: String_type::get()
void toString ()
Description:
  • see: string_type::get()

Redefinition of: SerializeableObject::toString()

return a upper-cased version of the string
string &toUpperCase ()
Description:
  • see: string_type::tolowercase()
  • name: string_type::touppercase()
  • access: public
OO-Alias of: trim(), chop()
string &trim ()
Description:
  • name: string_type::trim()
  • access: public
wrap a long text
string &wrap (
int $width, [string $break = ""], [bool $cut = false]
)
List of parameters:
Name Type Description
$width int (optional)
$break string (optional)
$cut bool (optional)
Description:

Note: THIS FUNCTION IS NOT BINARY-SAFE!

  • name: string_type::wrap()
  • access: public
inherited from base classes

Inherited From SerializeableObject

Documentation generated on Fri, 10 Nov 2006 00:35:42 +0100 by phpDocumentor 1.3.0RC4

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