Monday, September 4th, 2006 (updated 5 Oct ’10)

Documentation for PHPStringFun v1.2.1



The plugin works on both EE v1.x and v2.x.


EE v1.x

Place the pi.phpstringfun.php file in the /system/plugins directory.

EE v2.x

Create in the /system/expressionengine/third_party directory a directory /phpstringfun, then place the pi.phpstringfun.php file in there.



If the function’s result is an array, such as explode, the array_index parameter allows you to set which result from the array to produce. Also see the separator parameter.

function (required)

PHPStringFun requires the “function” parameter to be a PHP string function. Some functions cannot be used. These are fprintf() and implode().

Those that can be used are: 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, urlencode, vfprintf, vprintf, vsprintf, wordwrap.


Some functions work better if the order that the plugin accepts parameters is reversed. For instance, the explode function works better when reverse is set to “yes”, allowing the delimiter to be set as a parameter and the string to come within the body of the plugin.

par1, part2, par3, par4 and par5

What comes between the tags is essentially the initial parameter. Phpstringfun 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.


If the output of the plugin is an array, the separator parameter lets you set which character separates the items in the array. Also see the array_index parameter.


For example:

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

would return “te”.

{exp:phpstringfun function="explode" par1="," separator="|" reverse="y"}one,and.two,and,three{/exp:phpstringfun} 

would return “one|and.two|and|three|” while

{exp:phpstringfun function="explode" par1="," array_index="2" reverse="y"}one,and.two,and,three{/exp:phpstringfun} 

would return “and”.


Thanks to Derek Jones for making me clean up the (rather sparse) code and Ingmar Greil and Mark Bowen for giving it lovin’ on the forums.

Tue 14 Sep ’10


When using the explode function how would print the array? The tag just outputs “array”

Tue 14 Sep ’10

Adam Khan

This problem has come up before (see—I’ll take a look and see if I can figure out what’s happening.

Tue 14 Sep ’10


Thanks Adam. I want to explode a custom field of ids (123|43|75) so I can use them separately. If the explode function returns an array I don’t understand how phpstringfun would handle that.

Wed 15 Sep ’10

Adam Khan

Yes, it would have to check whether the result is an array and if so, output it as an array, taking a new parameter as the separator character.

Wed 15 Sep ’10

Adam Khan

Mike, I’ve updated the plugin to allow output from explode, but I think phpstringfun is not really worth using for that. To be honest, I never use the plugin myself. I find it easier to just use PHP wherever required in an EE template. The majority of my EE templates have PHP enabled.

I use explodes whenever necessary combined with foreaches. I generally keep PHP at the default output parsing stage, and if that makes a PHP variable inaccessible, I just embed a template and pass the PHP variable.

Wed 15 Sep ’10


Thanks Adam! I’ll give both a try

Wed 15 Sep ’10


Thanks Adam, I’ll try both methods.

Sun 26 Sep ’10


New to EE here, I am getting the error:

Fatal error: Call to a member function fetch_param() on a non-object in / [ …edited…] system/expressionengine/third_party/phpstringfun/pi.phpstringfun.php on line 36

My call looks like:

{exp:phpstringfun function=“ucwords”}{field_x}{/exp:phpstringfun}

What am I doing wrong?

Sat 2 Oct ’10


Hi Adam,

I\ve just upgraded PHPStringFun in EE2.1 from version 1.1 (EEv1) to version 1.2 (EEv1) and immediately got the same error as Dean mentions above on one of the pages of my site that uses this plugin:

Fatal error: Call to a member function fetch_param() on a non-object in /home/myaccount/public_html/mysystem/expressionengine/third_party/phpstringfun/pi.phpstringfun.php on line 36

Here’s the code I’m using in the template that’s causing this (which worked fine and without error with the previous version):

{exp:phpstringfun function=“urlencode”}{page_uri}{/exp:phpstringfun}

Not sure if this is a bug with the latest version, or if I’m doing something wrong with my code/tags that has now been tightened up on with the new version?



Tue 5 Oct ’10


I am also haveing problems with phpstringfun as the 2 users above:Fatal error: Call to a member function fetch_param() on a non-object in /home/myaccount/public_html/mysystem/expressionengine/third_party/phpstringfun/pi.phpstringfun.php on line 36

Tue 5 Oct ’10

Adam Khan

My apologies people, I’ve been swamped with work and didn’t have time to get to this.

Turns out I didn’t test the plugin properly in EE2. The fatal error is now fixed in v1.2.1.

Wed 6 Oct ’10


Thanks Adam! Having issues downloading the new 1.2.1? I get the the agree button, then I get an url doesn’t exist error?

Wed 6 Oct ’10

Adam Khan

Oops, file renamed correctly.

Sun 28 Nov ’10


When I download the file, all I get is the EE1 version. I would love to get my hands on the EE2 version!


Thu 23 Dec ’10


Hi adam,

I would like to use str_replace. but I couldn’t find example.

{exp:phpstringfun function=“str_replace” par1=”.jpg”  par2=“_t.jpg”}{photo}{/exp:phpstringfun}

But it doesn’t work.
So, could you give me correct example?

Mon 10 Jan ’11

Adam Khan

Uno, sorry for the delay in replying—I’ve been out of commission.

PHP’s String Replace function has as its parameters $search, $replace, $subject, so it would help to use the plugin’s reverse parameter then do as follows:

{exp:phpstringfun function=“str_replace” par1=“_t.jpg” par2=”.jpg” }{photo}{/exp:phpstringfun}

Sun 16 Jan ’11


For some reason it doesn’t seem to be working with nesting. Am I doing something wrong?

{exp:phpstringfun function=“htmlentities”}{exp:phpstringfun function=“nl2br”}{title}{/exp:phpstringfun}{/exp:phpstringfun}

Sun 3 Apr ’11


Hi Adam,

I’m trying to use PHPStringFun (v1.2.1 on EE 2.x) on a segment in a title element, using the ucwords function, but it’s not applying anything:
{exp:phpstringfun function=“ucwords”}{segment_2}{/exp:phpstringfun}

I’ve changed the function to “strtoupper” and it works fine.  If I change the {segment_2} to a hardcoded string, e.g.:
{exp:phpstringfun function=“ucwords”}this is lowercase{/exp:phpstringfun}
then I get the correct desired result.

Any suggestions as to what I’m doing wrong?

Hopefully the solution is staring me in the face!

Fri 3 Jun ’11


I’m having the same problem as Clair, is there a way of chaining functions?

I’m trying to replace spaces with ‘-’ and make it lowercase, but just the closing tag is displayed.

Wed 15 Jun ’11


Just noticed that “addslashes” function doesn’t exist in this plugin, but “stripslashes’ is in there.

It was really easy to add it to the plugin.

Just thought you might want to update that little thing.

Wed 20 Jul ’11


This worked well for me but it would be really nice if it worked with nesting.

Fudged my way around it with what I needed to do but its ugly and I can see a situation arising where I will have to nest some of these functions and be SOL.

Mon 8 Aug ’11


Desperately needs nesting..

Mon 15 Aug ’11

Tom Chapin

When I extracted the archive for phpstringfun 1.2.1, I was confused because there was only one file (“pi.phpstringfun.php”) contained inside and I couldn’t tell if it was the file for EE1 or EE2.

I went ahead and created a folder in my EE2 installation at /system/expressionengine/third_party/phpstringfun/ and I placed the pi.phpstringfun.php file there inside it. Everything seems to be working correctly when I tried it out.

Tue 20 Sep ’11

Sten Van den Bergh

str_replace also doesn’t work for me. It replaces the whole word with the par2 parameter. So this code:

{exp:phpstringfun function=“str_replace” par1=“o” par2=”+” }hello world{/exp:phpstringfun}

outputs “+”

Wed 5 Oct ’11

Allan White

A question about this plugin (and by extension, the PHP functions it enables): Can it encode/escape for Javascript? I need to inject some HTML into a JS function that’s part of an EECMS template, and it would be soooo slick to do it on the fly.  Example of the formatting here: It seems different than HTML entity encoding. Thanks! Neat concept.

Sat 15 Oct ’11


Explode won’t work with a array_index of 0 because 0 is false…

if ($array_index)
if (isset($array_index))


Sat 15 Oct ’11



Be aware that ee trims the params or something so par1=” : ” won’t work :(

Wed 29 Aug ’12

Nathan Pitman

Hi there, I’ve been using this plug-in for a while on a site but a recent server upgrade to a more current version of PHP has the substr_count function playing up. I’ve not been able to nail the exact cause but it seems that the addition of the offset parameter might have something to do with it. :)

Thu 25 Oct ’12

Frank Heijkamp

I had problems with the plugin under EE version 2, had to comment all version 1 code out. Is it only me having this problem?
  //  global $TMPL;
  //  $version = “”;
  //  if ( $TMPL )
  //  {
  //      $version = “1”;
  //  }
  //  else
  //  {
  //      $version = “2”;
  //  }
  //  if ($version == “2”)
  //  {
  //      keep EE version 2 code
        $this->EE =& get_instance();
        $TMPL = $this->EE->TMPL;
  //  }

Mon 21 Mar ’16


good iTube Apk is a fairly exciting minute sized apk which lets you just download YouTube videos straight to the internal or itube free download This can be the main use of iTube from my perspective. iTube Music nice.

Mon 21 Mar ’16


good Andy these two or Bluestacis are greatest android emulators which enables user to run smart phone program into pc. Download Mobdro on PC It’s possible for you to go its webpage applying this link. mobdro for pc or computer nice.

Thu 24 Mar ’16


good download and install Vidmate app on your PC. Vidmate App downloaded full and also movies of different vidmatedownloadapp nice.

Sat 14 May ’16


Very Nice blog i like your effort.
ShowBox Apk Download on your android devices and enjoy live tv streaming.

Fri 20 May ’16


Along with the streaming, the app also gives you an option of downloading the video which can be watched offline when you don’t have an internet connection.
snaptube app download

Wed 1 Jun ’16

voot app

very nice post

Tue 28 Jun ’16


good which launched 1Channel addon. Phoenix addon Install salts on kodi and includes a huge collection of the repo’s required nice.

Wed 17 Aug ’16


good Xender is normally one of the world’s top rated request Xender Free software from Yahoo Take up Retail outlet. download xender nice.

Tue 30 Aug ’16


good that’s kept on your device’s recollection by only picking You TV Player you will find all the types. You can put a stream on download You TV Player nice.

Wed 12 Oct ’16


good any various other video participant for take up the video. mobdro download desired clips and videos on the world wide web, and nice.

Thu 6 Dec ’18

Denny Parker

the process you have shared compatibility, installation… $1 Domain Registration truly helpful to me and quite enthralling

Mon 17 Dec ’18


Thank you for sharing this exciting resource with me and the world. Wish you always luck.
Madalin Stunt Cars 2

Tue 8 Jan ’19


Thank you.  I’ve been looking for this

@ Tree Removal Augusta

Mon 21 Jan ’19

Alex Jacob

Thanks for helping people access their PHP string functions without activating PHP in the template.

Visit my link as well, the hunt game.

Thu 7 Feb ’19

Mario Martinez

Really been looking for something to get engaged in like this

-Johnny with Carmichael Senior Care

Wed 20 Feb ’19


Thank you for this sharing, I think it’s pretty cool

Wed 20 Feb ’19


Thanks, it’s fun to look back at these old plugins.

Owner at O’Fallon tree services

Post a comment





Your comment:

Please answer the following question to assure your intentions are honorable: What is the capital of France? (5 characters required)

Remember my personal information
Notify me of follow-up comments?