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

Class String

Description

«datatype» String

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

}

  • name: String
  • access: public

Located in /includes/class_string.php

Object
   |
   --String
Method Summary

Methods

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

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

  • name: String::__construct()
OO-Alias of: addslashes(), addcslashes()
string &addSlashes (
[string $charlist = ""]
)
List of parameters:
Name Type Description
$charlist string a string of characters that should be escaped
Description:
  • name: String::addSlashes()
  • access: public
OO-Alias of: $string[$index]
void charAt (
int $index
)
List of parameters:
Name Type Description
$index int position of the character (starting with 0)
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::charAt()
  • access: public
clone the string
String cloneObject ()
Description:

creates a copy of this object

  • name: String::cloneObject()
  • access: public

Redefinition of: Object::cloneObject()

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

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

alias of cloneObject()
String copy ()
Description:
  • name: String::copy()
  • access: public
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.

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 used for entity conversion
$charset string used for entity conversion
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"

}

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

}

test two strings for equality
bool equals (
mixed $something
)
List of parameters:
Name Type Description
$something mixed some object that should be compared
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::equals()
  • access: public

Redefinition of: Object::equals()

get string value
string get ()
Description:

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

  • name: String::get()
  • access: public
convert to html entities
string htmlEntities (
string $input
)
List of parameters:
Name Type Description
$input string some string
Description:
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
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::indexOf()
  • access: public
get the length of the string
int length ()
Description:

Returns the number of characters in the string.

  • name: String::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.

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.

OO-Alias of: stripslashes(), stripcslashes()
string &removeSlashes (
string $charlist
)
List of parameters:
Name Type Description
$charlist string a string of characters that should be unescaped
Description:
  • name: String::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:

This will replace all entities of $needle with $substitute. Returns the number of times $needle is replaced.

replace a substring by using a regular expression
int replaceRegExp (
string $regularExpression, [string $substitute = ""], [int $limit = -1]
)
List of parameters:
Name Type Description
$regularExpression string
$substitute string (optional)
$limit int (optional) must be a positive integer > 0, defaults to -1 (no limit)
Description:

This will replace all hits of the Perl-compatible $regularExpression with $substitute.

Returns the number of times $needle is replaced.

reverse the string value
string &reverse ()
Description:
  • name: String::reverse()
  • access: public
set string value
string set (
string $value
)
List of parameters:
Name Type Description
$value string a new string value
Description:

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

  • name: String::set()
  • access: public
shuffle the string's characters
string &shuffle ()
Description:
  • name: String::shuffle()
  • access: public
convert string to an array
array split (
string $separator, int $limit
)
List of parameters:
Name Type Description
$separator string
$limit int
Description:
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
Description:
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::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::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::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::toInt()
  • access: public
return a lower-cased version of the string
string &toLowerCase ()
Description:
Alias of: String::get()
void toString ()
Description:

Redefinition of: Object::toString()

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

Inherited From Object

Documentation generated on Sun, 11 Mar 2007 15:02:46 +0100 by phpDocumentor 1.3.1

yana author: Thomas MeyerHomepage: www.yanaframework.net