Class SGL_String

Description

Various string helper methods.

Located in /SGL/String.php (line 53)


	
			
Method Summary
 static string censor (string $text)
 static string escapeSingleQuote (string $string)
 static array escapeSingleQuoteInArrayKeys (array $array)
 static boolean isCyrillic (string $str)
 static integer pseudoConstantToInt (string $string)
 static string replaceAccents (string $str)
 static string summarise (string $str, [integer $limit = 50], [integer $element = SGL_WORD], [string $appendString = ' ...'])
 string char2entity (string $char, [mixed $encoding = 'H'])
 string clean (string $var)
 void convertHighAscii ( $s)
 void dirify ( $s)
 string dispelMagicQuotes ( &$var, string $var)
 int formatBytes ( $size, [ $decimals = 1], [ $lang = '--'], int $bytes)
 string getCrlf ()
 string mungeMailAddress (string $address)
 string obfuscate (string $str)
 string obfuscate2 (string $str, [bool $bForLink = true])
 string obfuscate3 (string $address)
 void removeJs ( $var)
 string stripIniFileIllegalChars (string $string)
 string summariseHtml (string $str, [integer $lines = 10], string $appendString)
 string tidy (string $html, [bool $logErrors = false])
 void to7bit ( $text)
 void toValidFileName ( $origName)
 void toValidVariableName ( $str)
 string translate (string $key, [string $filter = false], [array $aParams = array()], [string $langCode = null])
 string translate2 (string $key, [string $filter = false], [array $aParams = array()], string $langCode)
 void trimWhitespace ( $var)
Methods
static censor (line 64)

Censors profanity.

string censor (string $text)
  • string $text: string to check
static escapeSingleQuote (line 859)

Esacape single quote.

string escapeSingleQuote (string $string)
  • string $string
static escapeSingleQuoteInArrayKeys (line 875)

Escape single quotes in every key of given array.

  • access: public
array escapeSingleQuoteInArrayKeys (array $array)
  • array $array
static isCyrillic (line 791)

Checks if strings has cyrillic chars.

boolean isCyrillic (string $str)
  • string $str
static pseudoConstantToInt (line 832)

Converts strings representing constants to int values.

Used for when constants are stored as strings in config.

integer pseudoConstantToInt (string $string)
  • string $string
static replaceAccents (line 773)

Replaces accents in string.

  • see: SGL_String::isCyrillic()
  • todo: make it work with cyrillic chars
  • todo: make it work with non utf-8 encoded strings
string replaceAccents (string $str)
  • string $str
static summarise (line 548)

Returns a shortened version of text string resolved by word boundaries.

  • return: Correctly shortened text.
  • access: public
string summarise (string $str, [integer $limit = 50], [integer $element = SGL_WORD], [string $appendString = ' ...'])
  • string $str: Text to be shortened.
  • integer $limit: Number of words/chars to cut to.
  • integer $element: What string element type to count by.
  • string $appendString: Trailing string to be appended.
char2entity (line 404)

Encode a given character to a decimal or hexadecimal HTML entity or to an hexadecimal URL-encoded symbol.

  • return: Encoded character (or raw char if unknown encoding)
  • author: Philippe Lhoste <PhiLho(a)GMX.net>
string char2entity (string $char, [mixed $encoding = 'H'])
  • string $char: Char to encode
  • mixed $encoding: 1 or D for decimal entity, 2 or H for hexa entity, 3 or U for URL-encoding, R for a random choice of any of the above, E for a random choice of any of the HTML entities.
clean (line 167)

Returns cleaned user input.

Instead of addslashing potential ' and " chars, let's remove them and get rid of any magic quoting which is enabled by default. Also removes any html tags and ASCII zeros

  • return: result.
  • access: public
string clean (string $var)
  • string $var: The string to clean.
convertHighAscii (line 683)
void convertHighAscii ( $s)
  • $s
dirify (line 669)
void dirify ( $s)
  • $s
dispelMagicQuotes (line 141)

If magic_quotes_gpc is in use, run stripslashes() on $var.

  • return: minus any magic quotes.
  • author: Chuck Hagenbuch <chuck@horde.org>
  • access: public
string dispelMagicQuotes ( &$var, string $var)
  • string $var: The string to un-quote, if necessary.
  • &$var
formatBytes (line 625)

Converts bytes to KB/MB/GB as appropriate.

  • return: B/KB/MB/GB
  • access: public
int formatBytes ( $size, [ $decimals = 1], [ $lang = '--'], int $bytes)
  • int $bytes
  • $size
  • $decimals
  • $lang
getCrlf (line 107)

Defines the <CR><LF> value depending on the user OS.

  • return: the <CR><LF> value to use
  • access: public
string getCrlf ()
mungeMailAddress (line 519)

Munge email addresses swapping plain text with html char entities as explained here: http://perso.crans.org/~raffo/aem/index.php.

string mungeMailAddress (string $address)
  • string $address
obfuscate (line 447)

Primarily used for obfuscating email addresses to prevent spam harvesting. Since it is URL-encoded, this can be used only in the href part of a <a> tag (mailto: scheme).

  • return: Encoded string
string obfuscate (string $str)
  • string $str: String to encode
obfuscate2 (line 465)

Primarily used for obfuscating email addresses to prevent spam harvesting.

string obfuscate2 (string $str, [bool $bForLink = true])
  • string $str: String to encode
  • bool $bForLink: true if used in the href part of a <a> tag, false to be used in HTML
obfuscate3 (line 493)

Lightweight function to obfuscate mail addresses: substitutes @ and dots in the domain part with a string.

string obfuscate3 (string $address)
  • string $address
removeJs (line 184)
void removeJs ( $var)
  • $var
stripIniFileIllegalChars (line 818)

Removes chars that are illegal in ini files.

string stripIniFileIllegalChars (string $string)
  • string $string
summariseHtml (line 592)

Returns a set number of lines of a block of html, for summarising articles.

  • todo: needs to handle orphan
string summariseHtml (string $str, [integer $lines = 10], string $appendString)
  • string $str
  • integer $lines
  • string $appendString
tidy (line 219)

Uses PHP tidy lib (http://www.coggeshall.org/tidy.php) if enabled and

extension is available. Cleans/corrects input html. If $logErrors is set to true and logging is set to true in default.conf.ini, tidy() will add entry to log with a string describing the errors and changes Tidy made via SGL::logMessage().

  • return: cleaned text
  • author: Andy Crain <andy@newslogic.com>
  • since: PHP 4.3
  • access: public
string tidy (string $html, [bool $logErrors = false])
  • string $html: the text to clean
  • bool $logErrors
to7bit (line 745)
void to7bit ( $text)
  • $text
toValidFileName (line 663)
void toValidFileName ( $origName)
  • $origName
toValidVariableName (line 651)
void toValidVariableName ( $str)
  • $str
translate (line 275)

Looks up key in current lang file (determined by preference) and returns target value.

  • todo: better integrate $lang handling
string translate (string $key, [string $filter = false], [array $aParams = array()], [string $langCode = null])
  • string $key: Translation term
  • string $filter: Optional filter fn
  • array $aParams
  • string $langCode: Pass the lang code for the language you wish to translate
translate2 (line 354)

Looks up key in current lang dictionary (SGL_Translation3) or specific language and returns target value.

string translate2 (string $key, [string $filter = false], [array $aParams = array()], string $langCode)
  • string $key: Translation term
  • string $filter: Optional filter fn
  • array $aParams: Optional params
  • string $langCode: Optional langCode to force translation in this language
trimWhitespace (line 117)
void trimWhitespace ( $var)
  • $var

Documentation generated on Tue, 23 Feb 2010 18:14:33 +0000 by phpDocumentor 1.4.3