blueshoes php application framework and cms            core_text
[ class tree: core_text ] [ index: core_text ] [ all elements ]

Class: Bs_TextUtil

Source Location: /core/text/Bs_TextUtil.class.php

Class Overview

Bs_Object
   |
   --Bs_TextUtil

dependencies: Bs_String, Bs_Array


Author(s):

Version:

  • 4.3.$Revision: 1.9 $ $Date: 2003/10/29 17:48:42 $

Copyright:

  • blueshoes.org

Methods


Inherited Variables

Inherited Methods

Class: Bs_Object

Bs_Object::Bs_Object()
Bs_Object::getErrors()
Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack.
Bs_Object::getLastError()
Basic error handling: Get last error string from the global Bs_Error-error stack.
Bs_Object::getLastErrors()
Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors().
Bs_Object::persist()
Persists this object by serializing it and saving it to a file with unique name.
Bs_Object::setError()
Basic error handling: Push an error string on the global Bs_Error-error stack.
Bs_Object::toHtml()
Dumps the content of this object to a string using PHP's var_dump().
Bs_Object::toString()
Dumps the content of this object to a string using PHP's var_dump().
Bs_Object::unpersist()
Fetches an object that was persisted with persist()

Class Details

[line 21]
dependencies: Bs_String, Bs_Array



Tags:

pattern:  singleton: (pseudostatic)
access:  public
version:  4.3.$Revision: 1.9 $ $Date: 2003/10/29 17:48:42 $
copyright:  blueshoes.org
author:  Andrej Arn <at blueshoes dot org>


[ Top ]


Class Methods


constructor Bs_TextUtil [line 39]

Bs_TextUtil Bs_TextUtil( )



[ Top ]

method abbreviateString [line 596]

string abbreviateString( string $text, [int $maxLength = 12])

To abbreviate a string to something meaningfull

Keep as much of the beginning string as possible and abbreviate starting at the end. NOTE: Only words with a beginning capital letter are abbreviated; the rest is trashed E.g.: Bs_TextUtil::abbreviateString('The Quick Red Fox', 12) // -> 'The Q. R. F.' Bs_TextUtil::abbreviateString('Hi, my name is Sam', 12) // -> 'Hi, my N. S.'




Parameters:

string   $text   the string to be abbreviated.
int   $maxLength   is the maximum number of characters in the new string.

[ Top ]

method getLanguageDependentValue [line 70]

string getLanguageDependentValue( mixed $var, [string $lang = 'en'])

returns the value of a [language dependant] [object] var for the current language.

example: you have a language setting var like $hello = array( 'en' =>'hello', 'en_us'=>'hi', 'en_uk'=>'good morning sir', 'de' =>'guten morgen', 'de_ch'=>'guete morge', ); now you want the best match for your language. examples: de_de => de fr => en (first entry) en_us => en_us




Tags:

throws:  NULL if var is not set [correctly].
access:  public


Parameters:

mixed   $var   (string or lang-hash.)
string   $lang   (like 'en' or 'en_uk'. default is 'en'.)

[ Top ]

method longestCommonSubstring [line 650]

string longestCommonSubstring( string $string1, string $string2)

finds the longest common substring of 2 strings and returns that part.

http://www.php.net/manual/en/ref.strings.php carl@youngbloods.org 09-Jan-2002 08:27 I've ported a function to PHP that will find the longest common substring in two different strings. Here it is: Here is where I found the original: http://www1.ics.uci.edu/~eppstein/161/960229.html




Tags:

return:  (substring)
access:  public


Parameters:

string   $string1  
string   $string2  

[ Top ]

method ordinal [line 529]

string ordinal( [int $num = 1])

returns the number as a string with it's ordinal value

examples: 1 => 1st 22 => 22nd 133 => 133rd 9 => 9th

thanks to: http://www.phpclasses.org/browse.html/file/1027.html




Tags:

todo:  what about zero '0'?
access:  public


Parameters:

int   $num  

[ Top ]

method parseSearchQuery [line 138]

array parseSearchQuery( string $string)

parses the search input we got from the user.

example: "+foobar -"hello world" AND blah"

i am not sure where to put that method. so i place it here into Bs_TextUtil. :/

 returns a vector filled with hashes that have the 3 keys:
   'phrase'   => the word like 'hello' or more if it was a phrase
                 in quotes like "pole position". it is the original
                 user input.
   'words'    => the words the user is looking for (vector).
                 if the "word" was in quotes like "hello world" then
                 this vector has more than 1 element.
   'operator' => the operator, one of & (and), | (or), ! (not).
   'fuzzy'    => bool, if a fuzzy search should be performed on that.
                 added in bs-4.5, experimental. (i kinda miss the
                 option to specify better what fuzzy searches to do,
                 and how to weight them. to soundex but no stemming? ...

 features:
   - boolean searches, examples:
      - "tom AND cherry"
      - "hello -world"
      - "tom UND cherry NOT foo bar lala blah"
   - support for quotes, eg "foobar AND "hello world""

 missing:
   - support for brackets, eg "foobar AND (hello OR world)"

all input is converted to lower case. Bs_String->normalize() is applied to the whole string. but no further converting is done, no check for noise words, no min/max word length etc. do that yourself.




Tags:

return:  (may be empty)
access:  public


Parameters:

string   $string  

[ Top ]

method parseSearchQuery2 [line 288]

array parseSearchQuery2( string $string)

parses the search input we got from the user.

example: "+foobar -"hello world" AND blah"

 returns a vector filled with hashes ...:

 features:
   - boolean searches, examples:
      - "tom AND cherry"
      - "hello -world"
      - "tom UND cherry NOT foo bar lala blah"
   - support for quotes, eg "foobar AND "hello world""
   - near searches, eg "tom near jerry"
   - fuzzy searches, eg "tom ~jerri". also stem searches, eg "jerr#".
   - brackets, eg "tom and (jerry or cherry)"

 missing:
   - support for "not near" searches.

all input is converted to lower case. Bs_String->normalize() is applied to the whole string. but no further converting is done, no check for noise words, no min/max word length etc. do that yourself.




Tags:

return:  (may be empty)
access:  public


Parameters:

string   $string  

[ Top ]

method percentUppercase [line 694]

int percentUppercase( string $string)

tells how many % of the given string are written in uppercase.

may be useful to modify a post to a bbs or detect it as spam/junk.




Tags:

return:  (number from 0 to 100.)


Parameters:

string   $string  

[ Top ]

method pluralS [line 552]

string pluralS( int $count)

determine whether to print a plural 's' or not

example: you want to print something like you have 5 product[s] in your basket. now if the user has 1 product, it should be without the 's', otherwise it should with 's'. even if there is no (0) product.

thanks to: http://www.phpclasses.org/browse.html/file/1027.html




Tags:

return:  ('s' or an empty string)
access:  public


Parameters:

int   $count  

[ Top ]

method shortenString [line 572]

string shortenString( string $text, int $length, [string $suffix = '...'])

To shorten a string to a certain number of characters, replacing surplus chars with a shortening suffix-string such as "[...]"

If shortening would make no sense, the original string is returned. Total string size (incl. suffix) is max the given length.




Tags:

author:  http://www.php.net/manual/en/ref.strings.php mail@philipp-louis.de 25-Apr-2001 09:02


Parameters:

string   $text   the string to be shortened.
int   $length   is the maximum number of characters in the new string
string   $suffix   (default is '...')

[ Top ]


Documentation generated on Mon, 29 Dec 2003 21:13:11 +0100 by phpDocumentor 1.2.3