1 of 2
1
Plugin: PHPStringFun
Posted: 05 September 2006 02:18 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  461
Joined  12-20-2002

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.

File Attachments
pi.phpstringfun.txt  (File Size: 4KB - Downloads: 1159)
 Signature 

Who ain’t a slave? - Ishmael

Profile
 
 
Posted: 14 November 2006 05:11 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  26056
Joined  05-14-2004

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

 Signature 
Profile
MSG
 
 
Posted: 15 November 2006 06:28 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  500
Joined  02-05-2002

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

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

Thanks Adam.

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

Profile
 
 
Posted: 17 November 2006 04:49 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1753
Joined  03-26-2006

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!

 Signature 

ryan masuga
—————
Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 17 November 2006 05:23 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1753
Joined  03-26-2006

Is there any obvious reason this isn’t working?

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

Results in:

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

 Signature 

ryan masuga
—————
Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 17 November 2006 05:24 PM   [ Ignore ]   [ # 5 ]  
Chancellor's Fellow
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  30387
Joined  04-29-2002

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

Profile
MSG
 
 
Posted: 17 November 2006 06:11 PM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1753
Joined  03-26-2006

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.

 Signature 

ryan masuga
—————
Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 27 December 2007 07:02 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  400
Joined  07-09-2006

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

 Signature 

Erwin van Lun,
futurist, founder Chatbots.org (virtual agent/assistant/chat bot community)

Profile
 
 
Posted: 27 December 2007 09:34 PM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1753
Joined  03-26-2006

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

 Signature 

ryan masuga
—————
Masuga Design | devot:ee
@masuga | @masugadesign | @devot_ee

Profile
 
 
Posted: 20 February 2008 03:03 PM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  2
Joined  11-06-2006

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)

Profile
 
 
Posted: 22 March 2008 02:07 PM   [ Ignore ]   [ # 10 ]  
Lab Assistant
RankRank
Total Posts:  131
Joined  03-05-2008

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.

Profile
 
 
Posted: 27 April 2008 03:15 AM   [ Ignore ]   [ # 11 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  191
Joined  12-24-2007

Mega-super-awesome-cool plugin.

 Signature 

Trifecta Interactive | Austin, TX

Profile
 
 
Posted: 10 June 2008 09:09 AM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1165
Joined  02-15-2008

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.

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter

Profile
 
 
Posted: 10 June 2008 09:45 AM   [ Ignore ]   [ # 13 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  461
Joined  12-20-2002

A toast!

 Signature 

Who ain’t a slave? - Ishmael

Profile
 
 
Posted: 14 June 2008 08:05 AM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1165
Joined  02-15-2008

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…

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter

Profile
 
 
Posted: 14 June 2008 08:35 AM   [ Ignore ]   [ # 15 ]  
Professor
Avatar
RankRankRankRankRankRankRank
Total Posts:  13725
Joined  04-15-2006

Hi Andy,

Just gave it a try here and couldn’t get it to work but I am wondering looking at the documentation page on php.net for money_format and seeing these notes :

Note: The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.

Note: The LC_MONETARY category of the locale settings, affects the behavior of this function. Use setlocale() to set to the appropriate default locale before using this function.

Wonder if those have anything to do with it at all? There is at least one other function in this plugin which I couldn’t get to work some time back. Can’t quite remember which one it was now but overall this really is a fantastic plugin. I see the way it works so I am thinking that this is probably more a server issue than the plugin. I could be wrong on that though.

Don’t know if that helps at all?

Best wishes,

Mark

 Signature 

Shopping Cart Plugin | Full List Of Add-Ons | About Me
——————————————————————————————
2.x Bug Tracker | Upgrade Errors

Profile
 
 
Posted: 21 June 2008 10:31 PM   [ Ignore ]   [ # 16 ]  
Summer Student
Avatar
Total Posts:  24
Joined  09-14-2006

Will this work within a weblog tag? I’m able to get it to work on hard-coded text, but that seems kinda pointless, I need it to work on the fly for a weblog:entries tag, kinda like so:

{exp:weblog:entries weblog="default"}
     {exp
:phpstringfun function="ltrim" par1="status:"}{body}{/exp:phpstringfun}<br />
{/exp:weblog:entries} 

So basically, if I was pulling in a list of items from a weblog, any items that had the text “status:”, would have that part trimmed.

The above code works if I replace {body} with hard-coded text (i.e. “Status: blah blah”) and would return just the “blah blah” portion. As soon as I go back to the {body} tag it doesn’t work.

Any ideas? Thanks!

Profile
 
 
Posted: 21 June 2008 10:51 PM   [ Ignore ]   [ # 17 ]  
Summer Student
Avatar
Total Posts:  24
Joined  09-14-2006

...and to make matters slightly more confusing…the above works when I use {title} tag, just not {body} tag. Like so:

{exp:weblog:entries weblog="default"}
     {exp
:phpstringfun function="ltrim" par1="status:"}{title}{/exp:phpstringfun}<br />
{/exp:weblog:entries} 
Profile
 
 
Posted: 22 June 2008 02:27 PM   [ Ignore ]   [ # 18 ]  
Summer Student
Avatar
Total Posts:  24
Joined  09-14-2006

I figured it out! When I was trying to get {body} it had a tag by default at the start, so doing a ltrim failed since the first item was the tag. I created a custom field for this instance so that I could set it as an input field vs. a text area so that it wouldn’t be wrapped by a tag….that did the trick.

Profile
 
 
   
1 of 2
1
 
‹‹ Widon’t      Plugin: Timesince ››