BlueShoes Application Framework made with PHP http://www.blueshoes.org/


Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: C:/usr/local/lib/php/blueshoes-4.2/core/util/Bs_String.class.php
BlueShoes Application Framework - util

Bs_String

Bs_Object
   |
  +-- Bs_String

This static class provides many useful string methods.

 

public class Bs_String extends Bs_Object

This static class provides many useful string methods.
Caution: there is a problem with php's strToUpper() and strToLower().the manual reads: Note that 'alphabetic' is determined by thecurrent locale. This means that in i.e. the default "C" locale,characters such as umlaut-A (Ä) will not be converted.many functions (in this class and everywhere else) use the 2functions. so expect problems with äöüéAÖÜ and the like. i thinkwe'd need selfmade implementations which convert any chars, notregarding 'default "C" locale'. i wish php would come with paramsfor the functions.http://www.php.net/manual/en/function.strtoupper.phpdeveloper@i-space.org 26-Feb-2002 01:48use this to convert to cyrillic (bulgarian) upper and lower version of your string :$term = "Íåùî";$upper_term = strtr($term, "àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ","ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÜÚÞß");$lower_term = strtr($term, "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÜÚÞß","àáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ");no dependencies here.

Authors,
Version4.0.$id$
Copyrightblueshoes.org

 

Methods inherited from Bs_Object

isex, isexception, tostring, tohtml, persist, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean

Public Method Summary

string

left(string $haystack, integer $num)

returns $num chars from the left side of $haystack
string

right(string $haystack, integer $num)

returns $num chars from the right side of $haystack
string

mid(string $haystack, [ integer $start ], integer $num)

returns $num chars from the middle of $haystack, beginning with $start (included).
bool

insert(string &$hayStack, string $addThis, int $position)

Insert $addThis into $haystack at $position.
void

removeFromToInt(string $string, int $from, int $to)

removes a part of a $string. starts at $from, ends at $to.
void

removeFromNumInt(string $string, int $from, int $num)

removes a part of a $string. starts at $from, removes $num chars.
bool

inStr(string $haystack, string $needle)

Tells if needle is part of haystack
bool

inStrI(string $haystack, string $needle)

same as inStr() but not case sensitive.
bool

startsWith(string $haystack, string $needle, [ string $ignoreSpaces ])

tells whether $haystack starts with $needle. eg "hello world" starts with "hello".
bool

startsWithI(string $haystack, string $needle, [ string $ignoreSpaces ])

same as startsWith() but not case sensitive.
bool

endsWith(string $haystack, string $needle, [ string $ignoreSpaces ])

tells whether $haystack ends with $needle. eg "hello world" ends with "world".
bool

endsWithI(string $haystack, string $needle, [ string $ignoreSpaces ])

same as endsWith() but not case sensitive.
int

strrpos(string $haystack, string $needle, [ string $offset ])

same as php's strrpos() but allows a string (instead of a char) as 2nd param and
string

oneOf()

Return one of the given arguements randomly.
bool

hasSpecialChars(string $myString, [ integer $charSet, string $myExceptions ])

tells whether there are "special" characters in a string or not.
string

normalize(string $param, [ string $specialDouble ])

Converts each special character (áéíÁÈÒÖ...) to their normal character (aeiAEOO...)
string

ucWords(string $string, [ string $addChars ])

Uppercase the first character of each word in a string.
string

escapeForRegexp(string $string, [ string $escapeChar ])

sometimes you want to include a string in a regular expression, but the
string

wrapLines(string $str, int $num, [ string $breakString, string $doHardBreak, string $doBreakHtml ])

Wrap lines in $str at character $num and return a new string.
void

Bs_String()

Warning: documentation is missing.

Private Method Summary

void

rtrim( $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $needle, $needle, $needle, $needle, $needle, $needle, $needle, $needle, $ignoreSpaces, $ignoreSpaces, $ignoreSpaces, $ignoreSpaces, $ignoreSpaces, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $needle, string $ignoreSpaces)

Warning: documentation is missing.
void

clean(string $str, string $type)

This function strips off certain characters from the passed string based on
bool

isUpper(string $string)

Tells if the given string is all uppercase.
bool

isLower(string $string)

Tells if the given string is all lowercase.
void

addLineNumbers(string &$str, [ integer $start, integer $indent ])

Add line number to the left of a given string.
void

sow( $string, $insert, $increment)

Inserts a string into another string every increment.
void

rot13( $rot13text)

ROT13 function - a function to encode and decode text strings
string

booleanSearchQuery([ string $searchString, string $searchFieldString ])

Sam: Does not belong here. Add to Db.
void

varDump( &$param)

Warning: documentation is missing.
void

text_object_dump( $name, $obj, string $prefix)

Warning: documentation is missing.

Private Constant Summary

BS_STRING_VERSION >>4.0.$x$<< Warning: documentation is missing.

Public Method Details

left

public string left( string $haystack, integer $num )

  returns $num chars from the left side of $haystack

Parameter
string $haystack
the string to be looked at
integer $num
Warning: documentation is missing.
Returns string

See Also right(), mid()

right

public string right( string $haystack, integer $num )

  returns $num chars from the right side of $haystack

Parameter
string $haystack
the string to be looked at
integer $num
Warning: documentation is missing.
Returns string

See Also left(), mid()

mid

public string mid( string $haystack, [ integer $start ], integer $num )

  returns $num chars from the middle of $haystack, beginning with $start (included).
note: $haystack begins with char 1, not with char 0. example:string "hello"number 12345

Parameter
string $haystack
the string to be looked at.
integer $start = >>1<<
begins at char 1 not 0!
integer $num
Warning: documentation is missing.
Returns string

See Also left(), right()

insert

public bool insert( string &$hayStack, string $addThis, int $position )

  Insert $addThis into $haystack at $position.
the first position of $haystack is 0 not 1.example: ($new will be 'hello')$old = 'hllo';$new = $Bs_String->insert($old, 'e', 1) OR $new='default';

Parameter
string &$hayStack
string $addThis
int $position
Returns bool

TRUE on success, FALSE on failure ($position is not >= 0 or the position is out of range).


removeFromToInt

public void removeFromToInt( string $string, int $from, int $to )

  removes a part of a $string. starts at $from, ends at $to.
caution: as usual pos numbers start at 0 not 1, see examples.examples: (see ecg)removeFromToInt('hello world', 2, 6); will return 'heorld'removeFromToInt('hello world', 0, 30); will return ''removeFromToInt('', 0, 30); will return ''

Parameter
string $string
int $from
int $to
Returns void


removeFromNumInt

public void removeFromNumInt( string $string, int $from, int $num )

  removes a part of a $string. starts at $from, removes $num chars.

Parameter
string $string
int $from
int $num
Returns void


inStr

public bool inStr( string $haystack, string $needle )

  Tells if needle is part of haystack
example:$haystack = "hello world";$needle = "lo";$x = $BsString->instr($haystack, $needle);true will be returned.

Parameter
string $haystack
the string to be looked at
string $needle
the string to be looked for
Returns bool

See Also inStrI()

inStrI

public bool inStrI( string $haystack, string $needle )

  same as inStr() but not case sensitive.

Parameter
string $haystack
the string to be looked at
string $needle
the string to be looked for
Returns bool

See Also inStr()

startsWith

public bool startsWith( string $haystack, string $needle, [ string $ignoreSpaces ] )

  tells whether $haystack starts with $needle. eg "hello world" starts with "hello".
if $ignoreSpaces is set to true, ltrim() will be used on $haystack.

Parameter
string $haystack
the string to be looked at
string $needle
the string to be looked for
string $ignoreSpaces = >>TRUE<<
default is true
Returns bool

See Also startsWithI()

startsWithI

public bool startsWithI( string $haystack, string $needle, [ string $ignoreSpaces ] )

  same as startsWith() but not case sensitive.

Parameter
string $haystack
the string to be looked at
string $needle
the string to be looked for
string $ignoreSpaces = >>TRUE<<
default is true
Returns bool

See Also startsWith()

endsWith

public bool endsWith( string $haystack, string $needle, [ string $ignoreSpaces ] )

  tells whether $haystack ends with $needle. eg "hello world" ends with "world".
if $ignoreSpaces is set to true, trim() will be used on $haystack. there is nofunction rtrim() in php :(

Parameter
string $haystack
the string to be looked at
string $needle
the string to be looked for
string $ignoreSpaces = >>TRUE<<
default is true
Returns bool

See Also endsWithI()

endsWithI

public bool endsWithI( string $haystack, string $needle, [ string $ignoreSpaces ] )

  same as endsWith() but not case sensitive.

Parameter
string $haystack
the string to be looked at
string $needle
the string to be looked for
string $ignoreSpaces = >>TRUE<<
default is true
Returns bool

See Also endsWith()

strrpos

public int strrpos( string $haystack, string $needle, [ string $offset ] )

  same as php's strrpos() but allows a string (instead of a char) as 2nd param and
$offset as 3rd param, just as php's strpos() does.if needle is not found, returns FALSE (just as the php function does).because 0 is a valid return value, check for === FALSE. this is the same problemas with the other such php functions.don't expect optimized code here. what we do is strpos() until the end, and thereturn the pos of the last found one. hack, but helps.examples: (see ecg)strrpos('abc <b>bold</b> abc', 'abc'); //will return 16strrpos('abc <b>bold</b> abc', 'abc', 5); //will return 0

Parameter
string $haystack
string $needle
string $offset = >>NULL<<
Returns int

the numeric position, first position = 0.

Throws bool FALSE.

oneOf

public string oneOf( )

  Return one of the given arguements randomly.
this function can take 0-n string params, so the following syntax is ok:$x = $Bs_String->oneOf();$x = $Bs_String->oneOf("hello");$x = $Bs_String->oneOf("hello", "world", "foobar", "something else", "", "bla bla bla");it will randomly pick one of the params and return it.this method has the disadvantage to take all arguements by value. some optimization can bedone bye using useOneOfArray($array) instead and passing the array by ref.if no arguement was given, an empty string is returned.

Returns string


hasSpecialChars

public bool hasSpecialChars( string $myString, [ integer $charSet, string $myExceptions ] )

  tells whether there are "special" characters in a string or not.
based on param $charSet, the following characters are considered 'normal':charSet 1 a-zcharSet 2 A-ZcharSet 3 a-z A-ZcharSet 4 0-9charSet 5 a-z 0-9charSet 6 A-Z 0-9charSet 7 a-z A-Z 0-9ascii codes:0-9 -> 048 - 057A-Z -> 065 - 090a-z -> 097 - 122other characters that need to be treated 'normal' can be given in the param array $myExceptions.

Parameter
string $myString
the string to be checked
integer $charSet = >>7<<
default is 7 (see abmove)
string $myExceptions = >>NULL<<
array with chars that should be considered as "normal" chars instead of "specials".
Returns bool


normalize

public string normalize( string $param, [ string $specialDouble ] )

  Converts each special character (áéíÁÈÒÖ...) to their normal character (aeiAEOO...)
This function is made to use special characters (192-223 and 224-255 in ascii table). (hope so)

Parameter
string $param
the string you want to be converted
string $specialDouble = >>TRUE<<
(translate some chars specially, like ä=>ae not ä=>a. default is TRUE.)
Returns string

the converted string.


ucWords

public string ucWords( string $string, [ string $addChars ] )

  Uppercase the first character of each word in a string.
Returns a string with the first character of each word in str capitalized,if that character is alphabetic.this method extends php's ucWords() function. php's implementation only convertscharacters after a 'whitespace characters':space, form-feed, newline, carriage return, horizontal tab,vertical tabhere you can define the characters yourself.recommended characters: the ones from php (see above)the minus "-" (i have coded the method because of this one)note: we face the strToUpper/Lower problem here that is described in the headerof this class (foreign characters like ä => Ä).

Parameter
string $string
string $addChars = >>null<<
(chars that should be treated like the default 'whitespace' chars.)
Returns string

@ecg tested


escapeForRegexp

public string escapeForRegexp( string $string, [ string $escapeChar ] )

  sometimes you want to include a string in a regular expression, but the
string might include such characters "^.[$()|*+?{\" in it. these needto be escaped (with a backslash).param $escapeChar:once you run the regexp, it will look like:preg_match('/^#/', $foo)you have start and end tags, here it's the foreslash "/". if the string you want to escape hereincludes these characters (foreslashes), they need to be escaped aswell. but since you can also do:preg_match('°^#/°, $foo)or anything else, you can specify your escape char in the 2nd param.

Parameter
string $string
string $escapeChar = >>'/'<<
(see above)
Returns string


wrapLines

public string wrapLines( string $str, int $num, [ string $breakString, string $doHardBreak, string $doBreakHtml ] )

  Wrap lines in $str at character $num and return a new string.
only line feeds \n are considered to be line breaks. carriage returns \r are not.on winblows, a newline is made with \n\r (or reverse, dunno). if both chars wouldbe considered as newlines, an input from windows would cause this method to make 2breaks instead of one. or this special case would need to be catched.if you want html breaks like <br> or <p> to be treated as newlines, replace thembefore using this method.if doHardBreak is set to true and doBreakHtml to false (this is the default behavior),then something like <somelongtag> won't be broken. this could cause html not to workproperly. but something like <tag parameter> would still be broken at the space, whichdoesn't affect html from working properly.example:wrapLines('this is my string and it is veeeeery long', 6)will return-----------thisis mystringand itisveeeeerylong-----------note: all lines in the example above do have a \n at the end, except the last one.

Parameter
string $str
the string to look at and return reformatted
int $num
the number of the character at which the line should be broken
string $breakString = >>"\n"<<
default is "\n", can also be '<br>' or "\n\r" this is the char that is inserted to break the string.
string $doHardBreak = >>TRUE,<<
default is true
string $doBreakHtml = >>FALSE<<
default is false
Returns string

Copyright this code snippet was found on phpbuilder.com with no license or copyright message. modified alot. Sam: Is this function of use ???? Check PHP's wordwrap. (PHP 4 >= 4.0.2) wordwrap -- Wraps a string to a given number of characters using a string break character. Description string wordwrap (string str [, int width [, string break [, int cut]]]) Wraps the string str at the column number specified by the (optional) width parameter. The line is broken using the (optional) break parameter. wordwrap() will automatically wrap at column 75 and break using '\n' (newline) if width or break are not given. If the cut is set to 1, the string is always wrapped at the specified width. So if you have a word that is larger than the given width, it is broken appart.

Bs_String

public void Bs_String( )

 

Warning: documentation is missing.

Returns void


Private Method Details

rtrim

private void rtrim( $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $needle, $needle, $needle, $needle, $needle, $needle, $needle, $needle, $ignoreSpaces, $ignoreSpaces, $ignoreSpaces, $ignoreSpaces, $ignoreSpaces, $haystack, $haystack, $haystack, $haystack, $haystack, $haystack, $needle, string $ignoreSpaces )

 

Warning: documentation is missing.

Parameter
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$needle
Warning: documentation is missing.
$needle
Warning: documentation is missing.
$needle
Warning: documentation is missing.
$needle
Warning: documentation is missing.
$needle
Warning: documentation is missing.
$needle
Warning: documentation is missing.
$needle
Warning: documentation is missing.
$needle
Warning: documentation is missing.
$ignoreSpaces
Warning: documentation is missing.
$ignoreSpaces
Warning: documentation is missing.
$ignoreSpaces
Warning: documentation is missing.
$ignoreSpaces
Warning: documentation is missing.
$ignoreSpaces
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$haystack
Warning: documentation is missing.
$needle
Warning: documentation is missing.
string $ignoreSpaces
Warning: documentation is missing.
Returns void


clean

private void clean( string $str, string $type )

  This function strips off certain characters from the passed string based on
the type specified.The following types are handled, default is 'alphanum':alpha -> removes !(a-z A-Z) noalpha -> removes a-z A-Znum -> removes !(0-9) nonum -> removes 0-9alphanum -> removes !(a-z A-Z 0-9) noalphanum -> removes a-z A-Z 0-9nohtmlentities -> remove things like &auml;to strip off html, still use php's strip_tags()

Parameter
string $str
string $type
Warning: documentation is missing.
Returns void


isUpper

private bool isUpper( string $string )

  Tells if the given string is all uppercase.

Parameter
string $string
Returns bool


isLower

private bool isLower( string $string )

  Tells if the given string is all lowercase.

Parameter
string $string
Returns bool


addLineNumbers

private void addLineNumbers( string &$str, [ integer $start, integer $indent ] )

  Add line number to the left of a given string.
E.g.echo addLineNumbers($s="aaaaa\n\nBBB\nddddd\n", $start=2);2: aaaaa3:4: BBB5: ddddd6:

Parameter
string &$str
integer $start = >>1<<
start the numbering with this number. Default is 1
integer $indent = >>3<<
min indent space on the left. Default is 3.
Returns void


sow

private void sow( $string, $insert, $increment )

  Inserts a string into another string every increment.
example: sow("hello world", "@", 3) => "hel@lo @wor@ld"

Parameter
$string
Warning: documentation is missing.
$insert
Warning: documentation is missing.
$increment
Warning: documentation is missing.
Returns void

Copyright nathan@cjhunter.com 29/08/2000 http://www.zend.com/codex.php?id=253&single=1

rot13

private void rot13( $rot13text )

  ROT13 function - a function to encode and decode text strings
using the popular ROT13 method.Brett Burridge (brett@brettb.com)The function is called using something like:print ROT13("Hello World");Note that ROT13 does not encrypt strings, so do not use it if security is an issueAn ASP and JavaScript version of the function is available from:http://www.aspwatch.com/c/199934/d5D41863A588511D3ADCA00A0C9E95208.aspExampleprint ROT13("Hello World");

Parameter
$rot13text
Warning: documentation is missing.
Returns void


booleanSearchQuery

private string booleanSearchQuery( [ string $searchString, string $searchFieldString ] )

  Sam: Does not belong here. Add to Db.
Takes an altavista like search string "hello +world -foobar" and gives a part of a where clause for sql.please use the IndexServer for these things. it offers alot more and does it cleaner. ask andrej or tell him if you'regoing to use this function. thanx.NOTE: BETTER USE THE IndexServer!!no support for () yet, like "+hello AND (foo OR bar)"no support for "" yet, like "+"hello world" +"foo bar"for example we support this query:+this and this und this -notthis not notthis nicht nichtdasbut not ths one:"hello world" and (tom or tim)all user input is converted to lower case and trimmed. the following operators are accepted:and, und, +not, nicht, -or

Parameter
string $searchString = >>""<<
string that the user typed into the webform as keywords, example "hello +world -notthis and this und dieses nicht dashier not dasauchnicht", default = no keywords
string $searchFieldString = >>""<<
space separated list of db fields to search, example "caption street location", default = no fields
Returns string

returns a string with a part of a where clause for sql queries


varDump

private void varDump( &$param )

 

Warning: documentation is missing.

Parameter
&$param
Warning: documentation is missing.
Returns void


text_object_dump

private void text_object_dump( $name, $obj, string $prefix )

 

Warning: documentation is missing.

Parameter
$name
Warning: documentation is missing.
$obj
Warning: documentation is missing.
string $prefix
Warning: documentation is missing.
Returns void


Private Constant Details

BS_STRING_VERSION

define( BS_STRING_VERSION, >>4.0.$x$<< )
Case: default: case sensitive




Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta