We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: String Mill

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.

This plugin is inspired by Adam Khan’s PHPStringFun plugin. The aim is to enable to use PHP string functions in templates.

The difference between these two plugins is the following: in order to have more power over parse order String Mill supports variable pair {string_mill_area}{/string_mill_area}

PARAMETERS

For any results String Mill plugin requires the “function” parameter to be a PHP string function.

List of supported PHP functions:

addcslashes, bin2hex, chop, chr, chunk_split, convert_cyr_string, convert_uudecode, convert_uuencode, count_chars, crc32, crypt, echo, explode, get_html_translation_table, hebrev, hebrevc, html_entity_decode, htmlentities, htmlspecialchars_decode, htmlspecialchars, join, levenshtein, localeconv, ltrim, md5_file, md5, metaphone, money_format, nl_langinfo, nl2br, number_format, ord, parse_str, print, printf, quoted_printable_decode, quotemeta, rtrim, setlocale, sha1_file, sha1, similar_text, soundex, sprintf, sscanf, str_ireplace, str_pad, str_repeat, str_replace, str_rot13, str_shuffle, str_split, str_word_count, strcasecmp, strchr, strcmp, strcoll, strcspn, strip_tags, stripcslashes, stripos, stripslashes, stristr, strlen, strnatcasecmp, strnatcmp, strncasecmp, strncmp, strpbrk, strpos, strrchr, strrev, strripos, strrpos, strspn, strstr, strtok, strtolower, strtoupper, strtr, substr_compare, substr_count, substr_replace, substr, trim, ucfirst, ucwords, vfprintf, vprintf, vsprintf, wordwrap.

String Mill accepts up to five additional parameters (par1, part2, par3, par4 and par5) needed by the chosen PHP string function. These parameters must be in sequence, so that if there’s a par2 there must also be a par1.

To know how many parameters the function takes, see its PHP documentation.

For example,

{exp:string_mill function="rtrim" par1="st"}
  test
  {/exp:string_mill}

would return “te”.

Some functions cannot be used. These are fprintf() and implode().

VARIABLE PAIR

String Mill plugin supports optional {string_mill_area}{/string_mill_area} variable pair. Variable pair is used to mark an area which shoul be processed by {exp:string_mill} tag Variable pair can be useful when you need more control over parse order. This variable pair can have the same parameters as {exp:string_mill} tag. In case variable pair does not have parameters, those of the tag are used. For example, you can code as here

{exp:string_mill function="rtrim" par1="st"}
  blah blah blah
  {string_mill_area}
  test
  {/string_mill_area}
  blah blah blah
  {/exp:string_mill}

or as here

{exp:string_mill}
  blah blah blah
  {string_mill_area function="rtrim" par1="st"}
  test
  {/string_mill_area}
  blah blah blah
  {/exp:string_mill}

In both cases the result will be

blah blah blah te blah blah blah

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

Laisvunas – thanks for updating this. I use it all the time.

Can you clarify how the new tag helps with parse order?

Thanks, Matt

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi Matt,

One real life example which motivated me to code this plugin:

{exp:string_mill}
{exp:reeposition}

{reeposition:item}
Some code
{/reeposition:item}

{embed="template_group/template" value="{string_mill_area function="strip_tags"}{reeposition:put_item}{/string_mill_area}"}


{/exp:string_mill}
{/exp:reeposition}

Here parse order should be as follows:

1) code inside {reeposition:item}{/reeposition:item} var pair;

2) then the output should be placed into several places by Reeposition plugin (exp:reeposition tag);

3) then inside “embed” variable’s parameter repositioned output should be stripped from HTML tags.

The problem was how to defer stripping of HTML tags until repositioning has taken place. I achieved this by introducing {string_mill_area}{/string_mill_area} variable pair which is used to delimit area parsed by String Mill plugin.

       
Laisvunas's avatar
Laisvunas
879 posts
about 16 years ago
Laisvunas's avatar Laisvunas

Hi,

I released version 1.0.1 of String Mill plugin.

In this release a bug was fixed - unneeded error message being outputted in certain cases.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.