contenido\includes\functions.api.string.php
Description: Contenido Strign API functions
Requirements:
- Author
- Timo A. Hummel
- Con_php_req
- 5.0
- Copyright
- four for business AG
- License
- http://www.contenido.org/license/LIZENZ.txt
- Link
- http://www.4fb.de
- Link
- http://www.contenido.org
- Package
- Contenido Backend includes
- Since
- file available since contenido release <= 4.6 {@internal created 2003-08-08 modified 2008-06-25, Frederic Schneider, add security fix modified 2008-09-15, Murat Purc, add replacement of characters with diacritics modified 2009-04-30, Ortwin Pinke, CON-252 modified 2010-01-07, Ingo van Peren, CON-293 $Id: functions.api.string.php 1726 2012-01-04 13:12:30Z dominik.ziegler $: }}
- Version
- 1.6.0
Functions

capiStrCleanURLCharacters( $sString, $bReplace = false) : string
capiStrCleanURLCharacters: Removes or converts all "evil" URL characters.
This function removes or converts all characters which can make an URL invalid.
Clean characters include: - All characters between 32 and 126 which are not alphanumeric and aren't one of the following: _-.
Name | Type | Description |
---|---|---|
$sString | string The string to operate on | |
$bReplace | string If true, all "unclean" characters are replaced |
Type | Description |
---|---|
string | The resulting string |
- Author
- Timo A. Hummel
- Copyright
- four for business AG, http://www.4fb.de

capiStrRecodeString( $sString, $sourceEncoding, $targetEncoding) : string
capiStrRecodeString: Converts a string to another encoding.
This function tries to detect which function to use (either recode or iconv).
If $sourceEncoding and $targetEncoding are the same, this function returns immediately.
For more information about encodings, refer to http://en.wikipedia.org/wiki/Character_encoding
For more information about the supported encodings in recode, refer to http://www.delorie.com/gnu/docs/recode/recode_toc.html
Note: depending on whether recode or iconv is used, the supported charsets differ. The following ones are commonly used and are most likely supported by both converters:
- ISO-8859-1 to ISO-8859-15
- ASCII
- UTF-8
Name | Type | Description |
---|---|---|
$sString | string The string to operate on | |
$sourceEncoding | string The source encoding (default: ISO-8859-1) | |
$targetEncoding | string The target encoding (if false, use source encoding) |
Type | Description |
---|---|
string | The resulting string |
- Author
- Timo A. Hummel
- Copyright
- four for business AG, http://www.4fb.de
- Todo
- Check if the charset names are the same for both converters
- Todo
- Implement a converter and charset checker to ensure compilance.

capiStrReplaceDiacritics( $sString, $sourceEncoding = "ISO-8859-1", $targetEncoding = "ISO-8859-1") : void
Name | Type | Description |
---|---|---|
$sString | ||
$sourceEncoding | ||
$targetEncoding |

capiStrTrimAfterWord( $string, $maxlen) : string
capiStrTrimAfterWord: Trims a string to a given length and makes sure that all words up to $maxlen are preserved, without exceeding $maxlen.
Warning: Currently, this function uses a regular ASCII-Whitespace to do the seperation test. If you are using ' ' to create spaces, this function will fail.
Example: $string = "This is a simple test"; echo capiStrTrimAfterWord ($string, 15);
This would output "This is a", since this function respects word boundaries and doesn't operate beyond the limit given by $maxlen.
Name | Type | Description |
---|---|---|
$string | string The string to operate on | |
$maxlen | int The maximum number of characters |
Type | Description |
---|---|
string | The resulting string |

capiStrTrimHard( $string, $maxlen, $fillup = "...") : string
capiStrTrimHard: Trims a string to a specific length.
If the string is longer than $maxlen, dots are inserted ("...") right before $maxlen.
Example: $string = "This is a simple test"; echo capiStrTrimHard ($string, 15);
This would output "This is a si...", since the string is longer than $maxlen and the resulting string matches 15 characters including the dots.
Name | Type | Description |
---|---|---|
$string | string The string to operate on | |
$maxlen | int The maximum number of characters | |
$fillup |
Type | Description |
---|---|
string | The resulting string |

capiStrTrimSentence( $string, $approxlen, $hard = false) : string
capiStrTrimSentence: Trims a string to a approximate length.
Sentence boundaries are preserved.
The algorythm inside calculates the sentence length to the previous and next sentences. The distance to the next sentence which is smaller will be taken to trim the string to match the approximate length parameter.
Example:
$string = "This contains two sentences. "; $string .= "Lets play around with them. ";
echo capiStrTrimSentence($string, 40); echo capiStrTrimSentence($string, 50);
The first example would only output the first sentence, the second example both sentences.
Explanation:
To match the given max length closely, the function calculates the distance to the next and previous sentences. Using the maxlength of 40 characters, the distance to the previous sentence would be 8 characters, and to the next sentence it would be 19 characters. Therefore, only the previous sentence is displayed.
The second example displays the second sentence also, since the distance to the next sentence is only 9 characters, but to the previous it is 18 characters.
If you specify the boolean flag "$hard", the limit parameter creates a hard limit instead of calculating the distance.
This function ensures that at least one sentence is returned.
Name | Type | Description |
---|---|---|
$string | string The string to operate on | |
$approxlen | int The approximate number of characters | |
$hard | boolean If true, use a hard limit for the number of characters (default: false) |
Type | Description |
---|---|
string | The resulting string |