Class String

Description

The String:: class provides static methods for charset and locale safe string manipulation.

$Horde: framework/Util/String.php,v 1.43.6.38 2009/09/15 16:36:14 jan Exp $

Copyright 2003-2009 The Horde Project (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.

Located in /Util/String.php (line 20)


	
			
Method Summary
 mixed convertCharset (mixed $input, string $from, [string $to = null])
 boolean extensionExists (string $ext)
 boolean isAlpha ($string $string, [$charset $charset = null])
 boolean isLower ($string $string, [$charset $charset = null])
 boolean isUpper (string $string, [string $charset = null])
 string length (string $string, [string $charset = null])
 string lower (string $string, [boolean $locale = false], [string $charset = null])
 string pad (string $input, integer $length, [string $pad = ' '], [const $type = STR_PAD_RIGHT], [string $charset = null])
 integer pos (string $haystack, string $needle, [integer $offset = 0], [string $charset = null])
 array regexMatch (string $text, array $regex, [string $charset = null])
 void setDefaultCharset (string $charset)
 string substr (string $string, integer $start, [integer $length = null], [string $charset = null])
 string ucfirst (string $string, [boolean $locale = false], [string $charset = null])
 string upper (string $string, [boolean $locale = false], [string $charset = null])
 string wordwrap (string $string, [integer $width = 75], [string $break = "\n"], [boolean $cut = false], [string $charset = null], [boolean $line_folding = false])
 string wrap (string $text, [integer $length = 80], [string $break_char = "\n"], [string $charset = null], [boolean $quote = false])
Methods
convertCharset (line 76)

Converts a string from one charset to another.

Works only if either the iconv or the mbstring extension are present and best if both are available. The original string is returned if conversion failed or none of the extensions were available.

  • return: The converted input data.
mixed convertCharset (mixed $input, string $from, [string $to = null])
  • mixed $input: The data to be converted. If $input is an an array, the array's values get converted recursively.
  • string $from: The string's current charset.
  • string $to: The charset to convert the string to. If not specified, the global variable $_HORDE_STRING_CHARSET will be used.
extensionExists (line 31)

Caches the result of extension_loaded() calls.

  • return: Is the extension loaded?
  • see: Util::extensionExists()
boolean extensionExists (string $ext)
  • string $ext: The extension name.
isAlpha (line 596)

Returns true if the every character in the parameter is an alphabetic character.

  • return: True if the parameter was alphabetic only.
boolean isAlpha ($string $string, [$charset $charset = null])
  • $string $string: The string to test.
  • $charset $charset: The charset to use when testing the string.
isLower (line 628)

Returns true if ever character in the parameter is a lowercase letter in the current locale.

  • return: True if the parameter was lowercase.
boolean isLower ($string $string, [$charset $charset = null])
  • $string $string: The string to test.
  • $charset $charset: The charset to use when testing the string.
isUpper (line 643)

Returns true if every character in the parameter is an uppercase letter in the current locale.

  • return: True if the parameter was uppercase.
boolean isUpper (string $string, [string $charset = null])
  • string $string: The string to test.
  • string $charset: The charset to use when testing the string.
length (line 370)

Returns the character (not byte) length of a string.

  • return: The string's part.
string length (string $string, [string $charset = null])
  • string $string: The string to return the length of.
  • string $charset: The charset to use when calculating the string's length.
lower (line 204)

Makes a string lowercase.

  • return: The string with lowercase characters
string lower (string $string, [boolean $locale = false], [string $charset = null])
  • string $string: The string to be converted.
  • boolean $locale: If true the string will be converted based on a given charset, locale independent else.
  • string $charset: If $locale is true, the charset to use when converting. If not provided the current charset.
pad (line 437)

Returns a string padded to a certain length with another string.

This method behaves exactly like str_pad but is multibyte safe.

  • return: The padded string.
string pad (string $input, integer $length, [string $pad = ' '], [const $type = STR_PAD_RIGHT], [string $charset = null])
  • string $input: The string to be padded.
  • integer $length: The length of the resulting string.
  • string $pad: The string to pad the input string with. Must be in the same charset like the input string.
  • const $type: The padding type. One of STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH.
  • string $charset: The charset of the input and the padding strings.
pos (line 403)

Returns the numeric position of the first occurrence of $needle in the $haystack string.

  • return: The position of first occurrence.
integer pos (string $haystack, string $needle, [integer $offset = 0], [string $charset = null])
  • string $haystack: The string to search through.
  • string $needle: The string to search for.
  • integer $offset: Allows to specify which character in haystack to start searching.
  • string $charset: The charset to use when searching for the $needle string.
regexMatch (line 661)

Performs a multibyte safe regex match search on the text provided.

  • return: The matches array from the first regex that matches.
  • since: Horde 3.1
array regexMatch (string $text, array $regex, [string $charset = null])
  • string $text: The text to search.
  • array $regex: The regular expressions to use, without perl regex delimiters (e.g. '/' or '|').
  • string $charset: The character set of the text.
setDefaultCharset (line 48)

Sets a default charset that the String:: methods will use if none is explicitly specified.

void setDefaultCharset (string $charset)
  • string $charset: The charset to use as the default one.
substr (line 319)

Returns part of a string.

  • return: The string's part.
string substr (string $string, integer $start, [integer $length = null], [string $charset = null])
  • string $string: The string to be converted.
  • integer $start: The part's start position, zero based.
  • integer $length: The part's length.
  • string $charset: The charset to use when calculating the part's position and length, defaults to current charset.
ucfirst (line 294)

Returns a string with the first letter capitalized if it is alphabetic.

  • return: The capitalized string.
string ucfirst (string $string, [boolean $locale = false], [string $charset = null])
  • string $string: The string to be capitalized.
  • boolean $locale: If true the string will be converted based on a given charset, locale independent else.
  • string $charset: The charset to use, defaults to current charset.
upper (line 249)

Makes a string uppercase.

  • return: The string with uppercase characters
string upper (string $string, [boolean $locale = false], [string $charset = null])
  • string $string: The string to be converted.
  • boolean $locale: If true the string will be converted based on a given charset, locale independent else.
  • string $charset: If $locale is true, the charset to use when converting. If not provided the current charset.
wordwrap (line 494)

Wraps the text of a message.

  • return: String containing the wrapped text.
  • since: Horde 3.2
string wordwrap (string $string, [integer $width = 75], [string $break = "\n"], [boolean $cut = false], [string $charset = null], [boolean $line_folding = false])
  • string $string: String containing the text to wrap.
  • integer $width: Wrap the string at this number of characters.
  • string $break: Character(s) to use when breaking lines.
  • boolean $cut: Whether to cut inside words if a line can't be wrapped.
  • string $charset: Character set to use when breaking lines.
  • boolean $line_folding: Whether to apply line folding rules per RFC 822 or similar. The correct break characters including leading whitespace have to be specified too.
wrap (line 563)

Wraps the text of a message.

  • return: String containing the wrapped text.
string wrap (string $text, [integer $length = 80], [string $break_char = "\n"], [string $charset = null], [boolean $quote = false])
  • string $text: String containing the text to wrap.
  • integer $length: Wrap $text at this number of characters.
  • string $break_char: Character(s) to use when breaking lines.
  • string $charset: Character set to use when breaking lines.
  • boolean $quote: Ignore lines that are wrapped with the '>' character (RFC 2646)? If true, we don't remove any padding whitespace at the end of the string.

Documentation generated on Sun, 30 Jan 2011 05:22:24 +0000 by phpDocumentor 1.4.3