Last active
December 14, 2015 03:10
-
-
Save tobias-forkel/ff19ee83f0c25c4542d8 to your computer and use it in GitHub Desktop.
Cut the text after a specific number of characters. If the max length is not reached, just output the text without modifications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Namespace ModuleName | |
* | |
* @category Namespace | |
* @package Namespace_ModuleName | |
* @copyright Copyright (c) 2015 Tobias Forkel (http://www.tobiasforkel.de) | |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | |
*/ | |
class Namespace_ModuleName_Helper_Data extends Mage_Core_Helper_Abstract | |
{ | |
/** | |
* Cut the text after a specific number of characters. | |
* If the max length is not reached, just output the text without modifications. | |
* | |
* If a word is longer then the max length, it will not work properly. Please extend this method | |
* to support strings without spaces. | |
* | |
* @param string $string Any kind of string. | |
* @param integer $maxlength The max length to output. | |
* | |
* @return string | |
*/ | |
public function truncateText($string = '', $maxlength = 10) | |
{ | |
return strtok(wordwrap($string, $maxlength, ' ...\n'), '\n'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment