• News
  • Developer information
  • Projects & contributions
  • Forum
  • Issue tracker
  • Open Funding
  • Security
  • User groups
  • Support
  • Store
  • Company

  • Path

    ez.no / exponential / documentation / development / libraries / ez template / operators / string handling


    String handling

    These documentation pages are no longer maintained. Please visit the new documentation site.

    [This functionality will appear in Exponential 3.2.]
    The string template class provides functionality for basic manipulation of strings. The table below contains a quick summary along with a short description of the currently available string operators. At the time of writing these operators only work with ASCII strings (except the ord and chr operator). Future versions will also work with Unicode. Detailed description of each operator can be found under this overview. You can also click on the name of an operator to jump to the corresponding description within this page.

    Some string operators also work with arrays, they are documented under Array handling.

    Operator

    Short description

    upcase

    Converts all alphabetical characters to uppercase.

    downcase

    Converts all alphabetical characters to lowercase.

    count_words

    Counts and returns the number of words found within a string.

    count_chars

    Counts and returns the number of characters (string length).

    trim

    Strips whitespace from beginning and/or end of a string.

    break

    Inserts HTML line breaks instead of newlines.

    wrap

    Wraps text to lines at a specified length.

    upfirst

    Converts the first character to uppercase.

    upword

    Converts all the first characters (in all words) to uppercase.

    simplify

    Transforms multiple consecutive characters into one.

    wash

    General text wash. Translates bogus strings to friendly ones.

    chr

    Returns a desired sequence of characters.

    ord

    Returns the ASCII/Unicode value of characters in a string.

    shorten

    Shortens a string to a few characters and adds a trailing sequence.

    pad

    Makes sure a string is at least n characters long.

    upcase

    Short summary:
    Converts all alphabetical characters to uppercase.

    Usage:
    $string|upcase( no parameters)

    Full description:
    This operator takes a string as input and returns it with all its alphabetical characters converted to uppercase.

    Example(s):

    {"My string is lame!"|upcase}

    returns the string "MY STRING IS LAME!"

    downcase

    Short summary:
    Converts all alphabetical characters to lowercase.

    Usage:
    $string|downcase( no parameters)

    Full description:
    This operator takes a string as input and returns it with all its alphabetical characters converted to lowercase.

    Example(s):

    {"My String Is CoOl!"|downcase}

    returns the string "my string is cool!"

    count_words

    Short summary:
    Counts and returns the number of words.

    Usage:
    $string|count_words( no parameters)

    Full description:
    This operator simply counts and returns the number of words (all of them) that are found within the inputted string.

    Example(s):

    {"Where do you want to publish today?"|count_words}

    returns an integer with its value set to 7

    count_chars

    Short summary:
    Counts and returns the number of characters (string length).

    Usage:
    $string|count_chars( no parameters)

    Full description:
    This operator simply counts and returns the number of characters (all of them) that are found within the inputted string. It basically returns the actual length of the string.

    Example(s):

    {"General protection fault!"|count_chars}

    returns an integer with its value set to 25

    trim

    Short summary:
    Strips whitespace from beginning and/or end.

    Usage:
    $string|trim( no parameters)

    Full description:
    The trim operator can be used to remove any unwanted whitespace from the beginning and/or the end of a string. Trim will get rid of the following characters:

    " "

    (ASCII 32 (0x20)), an ordinary space.

    " "

    (ASCII 9 (0x09)), a tab.

    ""

    (ASCII 10 (0x0A)), a new line (line feed).

    ""

    (ASCII 13 (0x0D)), a carriage return.

    ""

    (ASCII 0 (0x00)), the NUL-byte.

    "x0B"

    (ASCII 11 (0x0B)), a vertical tab.

    Example(s):

    {"    Gizmo is not a gremlin.  "|trim}

    returns the string "Gizmo is not a gremlin."

    break

    Short summary:
    Inserts HTML line breaks instead of newlines.

    Usage:
    $string|break( no parameters)

    Full description:
    This operator replaces any newline characters/sequences with a HTML break tag.

    Example(s):

    {"The lazy white
    
    cat
    
    jumps over
    
    the quick hamster.
    
    "|break}
    
     
    
    returns the string "The lazy white<br />cat<br />jumps over<br />the quick hamster."

    wrap

    Short summary:
    Wraps text to lines at a specified length.

    Usage:
    $string|wrap( [integer width [, string break_sequence [, boolean cut]]])

    Full description:
    By inserting newline ('') characters into the inputted string, this operator wraps a given text at a specified position. If the width parameter is omitted, it will automatically wrap at 80 (default specified in __FIX_ME__.ini). The break_sequence parameter specifies a string containing the desired break sequence to use, default is '' (newline). The cut parameter specifies wether the the string should always be wrapped at the specified width. In other words: if you have a word that is larger than the given width, it is broken apart.

    Example(s):

    {"Hello world"|wrap(5)}

    returns the string "Hello
    world"

    upfirst

    Short summary:
    Converts the first character to uppercase.

    Usage:
    $string|upfirst( no parameters)

    Full description:
    This operator simply converts the first character of a string to uppercase. (The very first letter becomes a capital letter.)

    Example(s):

    {"good bye cruel world!"|upfirst}

    returns the string "Good bye cruel world!"

    upword

    Short summary:
    Converts all the first characters (in all words) to uppercase.

    Usage:
    $string|upword( no parameters)

    Full description:
    The upfirst operator converts the first character of every word in a string to uppercase.

    Example(s):

    {"commodore amiga user"|upword}

    returns the string "Commodore Amiga User"

    simplify

    Short summary:
    Transforms multiple consecutive characters into one.

    Usage:
    $string|simplify( [string char_to_simplify])

    Full description:
    Transforms multiple consecutive characters into one. If you have a string with a lot of unnecessary whitespace (or dashes, whatever), you can use this operator to remove the duplicates leaving only a single copy of each character. The desired character to simplify can be specified using the char_to_simplify parameter, which by default is set to whitespace. Regexp style is used to specify special characters, please refer to the table below:

    tab

    (HT, TAB)

     

    newline

    (LF, NL)

     

    return

    (CR)

    f

    form feed

    (FF)

    a

    alarm (bell)

    (BEL)

    e

    escape (think troff)

    (ESC)

    Example(s):

    {"this____string__is___annoying"|simplify("_"}

    returns the string "this_string_is_annoying"

    wash

    Short summary:
    Translates bogus strings to friendly ones.

    Usage:
    $string|wash( [string washing_type])

    Full description:
    General character/string washing operator. The first (and only) parameter specifies the washing type: email or xhtml; xhtml is default. If you have a string that contains bogus characters (or sequences) that could mess up your page, you should "wash" the string before outputting it. Please refer to the first example.

    Example(s):

    {"bogus string <"|wash}
    
     
    
    returns the string "bogus string <"
    {"president@whitehouse.gov"|wash("email")}

    returns the string "president[at]whitehouse[dot]gov"

    chr

    Short summary:
    Returns the ASCII/UNICODE value of characters.

    Usage:
    $string|chr( no parameters)

    Full description:
    Returns the ASCII/UNICODE value of characters in input string.

    Example(s):

    {"abcdef"|ord}

    returns the array (97,98,99,100,101,102)

    ord

    Short summary:
    Returns a string of desired characters.

    Usage:
    array(integers)|ord( no parameters)

    Full description:
    Returns a sequence/string of desired characters. The characters are specified by their ASCII/Unicode values and inputted as an integer-array to the operator.

    Example(s):

    {array(97,98,99)|ord}

    returns the string "abc"

    shorten

    Short summary:
    Shortens string to a few characters and adds a trailing sequence.

    Usage:
    $string|shorten( [integer length [,string trailing_sequence]])

    Full description:
    Shortens string to length characters and adds a trailing sequence. Length also includes the length of the trailing sequence. If the input string is shorter than length it will not be shortened. The default length is __FIX_ME__ and the default trailing sequence is "...". These defaults can be modified in the __FIX_ME__.ini file.

    Example(s):

    {"This string is too long and needs to be shortened!"|shorten(17)}

    returns the string "This string is..."

    pad

    Short summary:
    Makes sure a string is at least n characters long.

    Usage:
    $string|pad( [integer length [,string pad_character]])

    Full description:
    Makes sure that the input string is at least length characters long by inserting extra characters at the end (padding). It is possible to specify what character to use with the pad_character parameter. Default pad character is whitespace.

    Example(s):

    {"Too short!"|pad(16)}

    returns the string "Too short! "

    {"Too short!"|pad(16,"-")}

    returns the string "Too short!------"

    Comments

    pad needs &nbsp option

    I think the pad function would be more useful if by default it padded non breaking spaces instead of just spaces, since the spaces wont appear in a web browser anyway. I can't find a way to override the pad character with nbsp.

    str_replace

    The str_replace function should be a part of the template-script-language. It's a very practical function.

    strip html tags

    to remove html tags from a string follow Paul's instruction:

    =============================
    In template.ini(.append.php)
    add under
    [PHP]
    ....
    PHPOperatorList[striptags]=strip_tags
    ......
    Then in your template use
    $yourstring_with_xml|striptags
    and catch the stripped output
    =============================

    See: http://ez.no/community/forum/developer/operator_to_strip_off_html_tags

    break

    We're working on the help page right now- it will show the break thingy as soon as I get to that part... Glad you like the new features; cheers!

    Great op. :)

    btw .. I was planing to write datatype for replaceing the \n to <br> befor storing it in the DB .. :)

    also the 'shorten' op. , great and really useful !

    well done , ezp just think what we need befor even say it :D

    break .. yeah :)

    Now am sure :)
    I asked becoz in the 'Example' doesn`t show that ;)

    break

    Selmah: Indeed, it does. Btw, the doc says "This operator replaces any newline characters/sequences with a HTML break tag." Right? :-)

    break

    this mean that will convert \n (new line) to <br/> ??!

    Contents

    Development

    Extensions
    Exponential datamodel
    Exponential tuning and stability
    Importing attribute data
    Kernel
    Libraries
        eZ xml
        eZ db
        eZ i18n
        eZ soap
        eZ template
           Basics
           Functions
           Operators
              Data fetch
              String handling
              Type handling
              Logical handling
              Arithmetics
              Control structure handling
              Array handling
              Image handling
              Miscellaneous
        eZ webdav
    Scripting
    Standards
    System overview
    Test Suite
    Using Doxygen to create API documenta...


    Created

    23/07/2003
    11:02:08 am
    by Balazs Halasy

    Last updated

    12/09/2003
    1:11:11 pm
    by Gunnstein Lye

    Authors

    Balazs Halasy
    Gunnstein Lye



    This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.