contenido\includes\functions.api.string.php

Show: PublicProtectedPrivateinherited
    Table of Contents
    Project: Contenido Content Management System

    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

    functioncapiStrCleanURLCharacters( $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: _-.

    Parameters
    NameTypeDescription
    $sString

    string The string to operate on

    $bReplace

    string If true, all "unclean" characters are replaced

    Returns
    TypeDescription
    stringThe resulting string
    Details
    Author
    Timo A. Hummel  
    Copyright
    four for business AG, http://www.4fb.de  
    functioncapiStrRecodeString( $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
    Parameters
    NameTypeDescription
    $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)

    Returns
    TypeDescription
    stringThe resulting string
    Details
    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.  
    functioncapiStrReplaceDiacritics( $sString,  $sourceEncoding = "ISO-8859-1",  $targetEncoding = "ISO-8859-1") : void

    Parameters
    NameTypeDescription
    $sString
    $sourceEncoding
    $targetEncoding
    functioncapiStrTrimAfterWord( $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 '&nbsp' 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.

    Parameters
    NameTypeDescription
    $string

    string The string to operate on

    $maxlen

    int The maximum number of characters

    Returns
    TypeDescription
    stringThe resulting string
    functioncapiStrTrimHard( $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.

    Parameters
    NameTypeDescription
    $string

    string The string to operate on

    $maxlen

    int The maximum number of characters

    $fillup
    Returns
    TypeDescription
    stringThe resulting string
    functioncapiStrTrimSentence( $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.

    Parameters
    NameTypeDescription
    $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)

    Returns
    TypeDescription
    stringThe resulting string
    Documentation was generated by phpDocumentor 2.0.0a12.