Another great helper is the string helper in the Magento core. It allows for some great manipulation of your strings. The best abilities are the remove accents and truncating strings methods.
Remove Accents
The first method is located in
Mage_Core_Helper_Data and
is called
removeAccents() . It does exactly what it says it will do, which is remove accents from your text. This is great for importing because Magento imports don’t really like foreign characters.
1 |
Mage::helper('core')->removeAccents($string); |
Truncate
The next method is located in
Mage_Core_Helper_String and is called
truncate() . More than just a simple strlen function, it has options to designate the amount of characters you want to show, if you want to display entire words, what to append at the end of your string, and even hands you back the remainder of the string to continue to work with.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$string = 'THIS IS THE TALE OF CAPTAIN JACK SPARROW, PIRATE SO BRAVE ON THE SEVEN SEAS A MYSTICAL QUEST TO THE ISLE OF TORTUGA, RAVEN LOCKS SWAY ON THE OCEAN\'S BREEZE'; // truncates full words up to 80 characters Mage::helper('core/string')->truncate($string); // truncates full words up to 40 characters Mage::helper('core/string')->truncate($string, 40); // Truncates full words up to 40 characters with right double angle brackets appended at the end. Mage::helper('core/string')->truncate($string, 40, '»'); // truncates full words up to 40 characters and passes the remaining characters to the $remainder variable Mage::helper('core/string')->truncate($string, 40, '...', $remainder); // truncates up to 40 characters ignoring full words and splitting at exactly 40 characters. Mage::helper('core/string')->truncate($string, 40, '...', $remainder, FALSE); |
Love it? Hate it? Want more? Leave me a comment and let me know!