cagartner
9/20/2016 - 1:53 PM

Trabalhando com string no Magento.

Trabalhando com string no Magento.

<?php
$remainder = '';
$string = 'Vestibulum lobortis mattis massa. Fusce malesuada mauris -et purus interdum venenatis.';
echo Mage::helper('core/string')->truncate($string, 50, '...', $remainder, true);
// Vestibulum lobortis mattis massa. Fusce malesuada mauris et purus interdum venenatis. Aliquam er...
echo Mage::helper('core/string')->truncate($string, 50, '...', $remainder, false);
// Vestibulum lobortis mattis mass
// malesuada mauris et purus interdum venenatis.a. Fusce malesuada mauris et purus interdum venenatis. Aliquam...
echo $remainder;
<?php
// splitWords($str, $uniqueOnly = false, $maxWordLength = 0, $wordSeparatorRegexp = '\s')
$string = 'I really really like turtles';
var_dump(Mage::helper('core/string')->splitWords($string));
/*
* array(5) {
*  [0]=>
*  string(1) "I"
*  [1]=>
*  string(6) "really"
*  [2]=>
*  string(6) "really"
*  [3]=>
*  string(4) "like"
*  [4]=>
*  string(7) "turtles"
*  }
*/
var_dump(Mage::helper('core/string')->splitWords($string, true));
/*
* array(4) {
*  ["I"]=>
*  string(1) "I"
*  ["really"]=>
*  string(6) "really"
*  ["like"]=>
*  string(4) "like"
*  ["turtles"]=>
*  string(7) "turtles"
*  }
*/
<?php
// splitInjection($str, $length = 50, $needle = '-', $insert = ' ')
$string = 'ABCDEFGHIKJLMNOPQRSTUVWXYZ';
echo Mage::helper('core/string')->splitInjection($string, 5, 'G');
// ABCDE FG HIKJLMNO PQRST UVWXY Z