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: PHPStringFun

Development and Programming

Adam Khan's avatar
Adam Khan
315 posts
18 years ago
Adam Khan's avatar Adam Khan

In response to a particular problem posed here on the forums, I copy’n’pasted together a quick plugin that acts as a gateway to PHP’s string functions without needing to activate PHP in a template. It’s attached to this post.

Derek made me improve it a bit, but he doesn’t want to add it to the main plugins repository until I’ve weeded out from it any PHP functions that won’t work within it. Rather than sit and test every PHP function, most of which I’ve never used and don’t know, I thought it might be easier to ask the community if they can see from the following list of PHP functions which ones will be problematic inside PHPStringFun.

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.

Whichever ones anybody points out I’ll remove from the array of allowed functions inside the plugin.

Hey, it’s worth a try.

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
18 years ago
Lisa Wess's avatar Lisa Wess

Do you know I never saw this? I added it to the wiki.

       
Cocoaholic's avatar
Cocoaholic
445 posts
18 years ago
Cocoaholic's avatar Cocoaholic

I remember seeing this post but I was to busy to try the plugin at that time… and forgot about it :red:

Great plugin, just did some testing and I absolutely love it!

Thanks Adam.

[EDIT] @Lisa, thanks for adding it to the Wiki.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
18 years ago
Ryan M.'s avatar Ryan M.

In my effort to remove as much PHP from my templates as possible, I will give this a shot. I just found a place where I’m using ‘str_replace’ so I’ll try re-doing that with this plugin, thanks!

       
Ryan M.'s avatar
Ryan M.
1,511 posts
18 years ago
Ryan M.'s avatar Ryan M.

Is there any obvious reason this isn’t working?

{exp:phpstringfun function="str_replace" par1="/" par2="x"}/blah/blah2/blah3{/exp:phpstringfun}

Results in:

x

That should replace every slash with an x, but it looks like it’s replacing the first one and stopping there. Any suggestions?

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
18 years ago
Sue Crocker's avatar Sue Crocker

Ryan, there already is a str_replace plugin. 😊 I don’t have the link to it handy, but you should be able to find it in the plugins list.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
18 years ago
Ryan M.'s avatar Ryan M.

Why, you’re right! Thanks!

For anyone else: Here’s the thread for the Find and Replace plugin, as created by Lodewijk. This plugin can also found on the Plugins page.

       
ErwinVanLun's avatar
ErwinVanLun
235 posts
17 years ago
ErwinVanLun's avatar ErwinVanLun

does anyone know what happened to the phpstringfun plugin? Can’t find it anymore!

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

Wait…isn’t it at the top of this thread?

       
Jonathan Youngblood's avatar
Jonathan Youngblood
2 posts
17 years ago
Jonathan Youngblood's avatar Jonathan Youngblood

i know this was posted a while ago, but i didn’t know about it until today. THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU (ad infinitum)

       
seajay's avatar
seajay
109 posts
17 years ago
seajay's avatar seajay

Don’t forget: when uploading to the plugins folder, change the extension from …

pi.phpstringfun.txt

… to …

pi.phpstringfun.php

Documentation is then available in the Plugins manager by clicking on the plugin name/link.

       
trif3cta's avatar
trif3cta
148 posts
17 years ago
trif3cta's avatar trif3cta

Mega-super-awesome-cool plugin.

       
Andy Harris's avatar
Andy Harris
958 posts
about 17 years ago
Andy Harris's avatar Andy Harris

This plugin is frickin’ excellent. So outstanding in fact, that today will forever be known to me as ‘phpstring fun day’. Mark it down everyone, 10th June.

       
Adam Khan's avatar
Adam Khan
315 posts
about 17 years ago
Adam Khan's avatar Adam Khan

A toast!

       
Andy Harris's avatar
Andy Harris
958 posts
16 years ago
Andy Harris's avatar Andy Harris

Has anyone gotten this to work with money_format? I have a string and I want to display it formatted in good old British Pounds Sterling. But I can’t get it to work…

       
1 2

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.