A String Helper Extension for `Capitalize` and `Start With` Methods - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: A String Helper Extension for `Capitalize` and `Start With` Methods (/showthread.php?tid=58573) |
A String Helper Extension for `Capitalize` and `Start With` Methods - El Forum - 06-25-2013 [eluser]SpYk3[/eluser] This nice little extension has been very handy over time with some very simple request. The `capitalize` method was originally taken from a PHP Doc posting. I've since molded into something a little more intuitive and suiting to modern day spelling of American English words, titles, names, and phrases. A second, `optional`, parameter is a Boolean for "is name". If you're seeking to capitalize a name, then pass `TRUE`, else, just leave it be. - capitalize('jd mckinstry', TRUE); // returns JD McKinstry - capitalize('merry christmas and happy holidays!')); // returns Merry Christmas and Happy Holidays! The second and third methods simply help to find if a string "starts" or "ends" with a specific "needle". - startsWith('billy bob', 'bob'); // returns bool(false) - startsWith('billy bob', 'billy'); // returns bool(true) - endsWith('billy bob', 'bob'); // returns bool(true) - endsWith('billy bob', 'billy'); // returns bool(false) Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); A String Helper Extension for `Capitalize` and `Start With` Methods - El Forum - 06-25-2013 [eluser]jairoh_[/eluser] you are a helper. you might wanna upload that on github sir |