Overview

Packages

  • Util

Classes

  • Horde_Array
  • Horde_Array_Sort_Helper
  • Horde_Domhtml
  • Horde_String
  • Horde_Util
  • Horde_Variables
  • Overview
  • Package
  • Class
  • Tree

Class Horde_String

Provides static methods for charset and locale safe string manipulation.

Copyright 2003-2012 Horde LLC (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Package: Util
Category: Horde
License: LGPL 2.1
Author: Jan Schneider jan@horde.org
Located at Horde/String.php
Methods summary
public static mixed
# convertCharset( mixed $input, string $from, string $to, boolean $force = false )

Converts a string from one charset to another.

Converts a string from one charset to another.

Uses the iconv or the mbstring extensions. The original string is returned if conversion failed or none of the extensions were available.

Parameters

$input
<p>The data to be converted. If $input is an an array, the array's values get converted recursively.</p>
$from
The string's current charset.
$to
The charset to convert the string to.
$force
Force conversion?

Returns

mixed
The converted input data.
public static string
# lower( string $string, boolean $locale = false, string $charset = null )

Makes a string lowercase.

Makes a string lowercase.

Parameters

$string
The string to be converted.
$locale
<p>If true the string will be converted based on a given charset, locale independent else.</p>
$charset
<p>If $locale is true, the charset to use when converting.</p>

Returns

string
The string with lowercase characters.
public static string
# upper( string $string, boolean $locale = false, string $charset = null )

Makes a string uppercase.

Makes a string uppercase.

Parameters

$string
The string to be converted.
$locale
<p>If true the string will be converted based on a given charset, locale independent else.</p>
$charset
<p>If $locale is true, the charset to use when converting. If not provided the current charset.</p>

Returns

string
The string with uppercase characters.
public static string
# ucfirst( string $string, boolean $locale = false, string $charset = null )

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

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

Parameters

$string
The string to be capitalized.
$locale
<p>If true the string will be converted based on a given charset, locale independent else.</p>
$charset
The charset to use, defaults to current charset.

Returns

string
The capitalized string.
public static string
# ucwords( string $string, boolean $locale = false, string $charset = null )

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

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

Sentences are splitted into words at whitestrings.

Parameters

$string
The string to be capitalized.
$locale
<p>If true the string will be converted based on a given charset, locale independent else.</p>
$charset
The charset to use, defaults to current charset.

Returns

string
The capitalized string.
public static string
# substr( string $string, integer $start, integer $length = null, string $charset = 'UTF-8' )

Returns part of a string.

Returns part of a string.

Parameters

$string
The string to be converted.
$start
The part's start position, zero based.
$length
The part's length.
$charset
<p>The charset to use when calculating the part's position and length, defaults to current charset.</p>

Returns

string
The string's part.
public static integer
# length( string $string, string $charset = 'UTF-8' )

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

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

Parameters

$string
The string to return the length of.
$charset
<p>The charset to use when calculating the string's length.</p>

Returns

integer
The string's length.
public static integer
# pos( string $haystack, string $needle, integer $offset = 0, string $charset = 'UTF-8' )

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

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

Parameters

$haystack
The string to search through.
$needle
The string to search for.
$offset
<p>Allows to specify which character in haystack to start searching.</p>
$charset
<p>The charset to use when searching for the $needle string.</p>

Returns

integer
The position of first occurrence.
public static integer
# rpos( string $haystack, string $needle, integer $offset = 0, string $charset = 'UTF-8' )

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

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

Parameters

$haystack
The string to search through.
$needle
The string to search for.
$offset
<p>Allows to specify which character in haystack to start searching.</p>
$charset
<p>The charset to use when searching for the $needle string.</p>

Returns

integer
The position of first occurrence.
public static string
# pad( string $input, integer $length, string $pad = ' ', const $type = STR_PAD_RIGHT, string $charset = 'UTF-8' )

Returns a string padded to a certain length with another string. This method behaves exactly like str_pad() but is multibyte safe.

Returns a string padded to a certain length with another string. This method behaves exactly like str_pad() but is multibyte safe.

Parameters

$input
The string to be padded.
$length
The length of the resulting string.
$pad
<p>The string to pad the input string with. Must be in the same charset like the input string.</p>
$type
<p>The padding type. One of STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH.</p>
$charset
<p>The charset of the input and the padding strings.</p>

Returns

string
The padded string.
public static string
# wordwrap( string $string, integer $width = 75, string $break = "\n", boolean $cut = false, boolean $line_folding = false )

Wraps the text of a message.

Wraps the text of a message.

Parameters

$string
String containing the text to wrap.
$width
<p>Wrap the string at this number of characters.</p>
$break
Character(s) to use when breaking lines.
$cut
<p>Whether to cut inside words if a line can't be wrapped.</p>
$line_folding
<p>Whether to apply line folding rules per RFC 822 or similar. The correct break characters including leading whitespace have to be specified too.</p>

Returns

string
String containing the wrapped text.
public static string
# wrap( string $text, integer $length = 80, string $break_char = "\n", boolean $quote = false )

Wraps the text of a message.

Wraps the text of a message.

Parameters

$text
String containing the text to wrap.
$length
Wrap $text at this number of characters.
$break_char
Character(s) to use when breaking lines.
$quote
<p>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.</p>

Returns

string
String containing the wrapped text.
public static string
# truncate( string $text, integer $length = 100 )

Return a truncated string, suitable for notifications.

Return a truncated string, suitable for notifications.

Parameters

$text
The original string.
$length
The maximum length.

Returns

string
The truncated string, if longer than $length.
public static string
# abbreviate( string $text, integer $length = 20 )

Return an abbreviated string, with characters in the middle of the excessively long string replaced by '...'.

Return an abbreviated string, with characters in the middle of the excessively long string replaced by '...'.

Parameters

$text
The original string.
$length
The length at which to abbreviate.

Returns

string
The abbreviated string, if longer than $length.
public static string
# common( string $str1, string $str2 )

Returns the common leading part of two strings.

Returns the common leading part of two strings.

Parameters

$str1
A string.
$str2
Another string.

Returns

string
The start of $str1 and $str2 that is identical in both.
public static boolean
# isAlpha( string $string, string $charset )

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

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

Parameters

$string
The string to test.
$charset
The charset to use when testing the string.

Returns

boolean
True if the parameter was alphabetic only.
public static boolean
# isLower( string $string, string $charset )

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

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

Parameters

$string
The string to test.
$charset
The charset to use when testing the string.

Returns

boolean
True if the parameter was lowercase.
public static boolean
# isUpper( string $string, string $charset )

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

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

Parameters

$string
The string to test.
$charset
The charset to use when testing the string.

Returns

boolean
True if the parameter was uppercase.
public static array
# regexMatch( string $text, array $regex, string $charset = null )

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

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

Parameters

$text
The text to search.
$regex
<p>The regular expressions to use, without perl regex delimiters (e.g. '/' or '|').</p>
$charset
The character set of the text.

Returns

array
The matches array from the first regex that matches.
public static boolean
# validUtf8( string $text )

Check to see if a string is valid UTF-8.

Check to see if a string is valid UTF-8.

Parameters

$text
The text to check.

Returns

boolean
True if valid UTF-8.

Since

1.1.0
public static string
# trimUtf8Bom( string $str )

Strip UTF-8 byte order mark (BOM) from string data.

Strip UTF-8 byte order mark (BOM) from string data.

Parameters

$str
Input string (UTF-8).

Returns

string
Stripped string (UTF-8).

Since

1.4.0
API documentation generated by ApiGen