• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inflector - humanize & underscore

#1
[eluser]Phil Sturgeon[/eluser]
They seem to break when only word is sent in.

Code:
echo humanize('foo'); // outputs nothing
echo humanize('foo_bar'); // outputs Foo Bar

My reccomendation to the team is to use my str_replace based functions instead. Its the most simply of changes but seems to work where the preg_replace ones dont.

Code:
// --------------------------------------------------------------------

/**
* Underscore
*
* Takes multiple words separated by spaces and underscores them
*
* @access    public
* @param    string
* @return    str
*/        
function underscore($str)
{
    return str_replace('_', ' ', strtolower(trim($str)));
}

// --------------------------------------------------------------------

/**
* Humanize
*
* Takes multiple words separated by underscores and changes them to spaces
*
* @access    public
* @param    string
* @return    str
*/        
function humanize($str)
{
    return ucwords(str_replace('_', ' ', strtolower(trim($str))));
}

Meanwhile if anyone else has this problem, just throw this into a custom /application/helpers/inflector_helper.php

#2
[eluser]Derek Allard[/eluser]
Thanks. Could you throw a report into the bug tracker for us?

#3
[eluser]roosterboy[/eluser]
But the preg_replace call is necessary to handle multiple consecutive whitespace characters and convert them into a single underscore (or vice versa).

thepyromaniac, are you sure nothing else is going on with your code? I have no trouble with the following:
Code:
echo humanize( 'foo' ); //outputs Foo
echo humanize( 'foo_bar' ); //outputs Foo Bar

#4
[eluser]esra[/eluser]
I'm not positive about this, but I believe that the original inflector code was based on a prerelease version of the inflector used for the Akelos framework. I seem to remember a post from Rick about this last summer. The inflector code was placed in the public domain long before the actual Akelos framework was released. I'm wondering if this issue was resolved in the release version of Akelos or later versions.

#5
[eluser]Derek Jones[/eluser]
If you are able to duplicate this problem (I also am not), please post to the Bug Tracker, and include your OS, PHP Version, and PCRE library version.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.