ExpressionEngine 7.5 has been Released! Learn More!
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.
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?
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.