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 |
|
|
|
|
|
|
| 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 |
|
|
|
|
|
|
| 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 |
|
|
|
|
|
|
| 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 |
$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 |
$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 |
$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 |
|