ez.no / exponential / documentation / development / libraries / ez template / operators / 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.
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!"
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!"
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
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
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."
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."
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"
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!"
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"
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"
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"
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)
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"
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..."
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   option
James Ward
Wednesday 22 June 2005 8:16:49 pm
str_replace
Martin Leblanc
Tuesday 14 December 2004 10:22:44 am
strip html tags
willy jansen
Wednesday 08 September 2004 8:54:02 am
=============================
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
Balazs Halasy
Wednesday 23 July 2003 4:18:36 pm
Great op. :)
Selmah Maxim
Wednesday 23 July 2003 3:55:55 pm
also the 'shorten' op. , great and really useful !
well done , ezp just think what we need befor even say it :D
break .. yeah :)
Selmah Maxim
Wednesday 23 July 2003 3:52:42 pm
I asked becoz in the 'Example' doesn`t show that ;)
break
Balazs Halasy
Wednesday 23 July 2003 3:43:59 pm
break
Selmah Maxim
Wednesday 23 July 2003 1:41:57 pm