Beispiel #1
0
 /**
  * Shorten a string to a specific length by truncating or abbreviating the string
  * 
  * QuickBooks often uses unusually short field lengths. This function can 
  * be used to try to make long strings fit cleanly into the QuickBooks 
  * fields. It tries to do a few things:
  * 	- Convert long words to shorter abbreviations
  * 	- Remove non-ASCII characters
  * 	- Truncate the string if it's still too long
  * 
  * @param string $value				The string to shorten
  * @param integer $length			The max. length the string should be
  * @param boolean $with_abbrevs		Whether or not to abbreviate some long words to shorten the string
  * @return string					The shortened string
  */
 protected static function _castTruncate($value, $length, $with_abbrevs = true)
 {
     $value = QuickBooks_Cast::_castCharset($value);
     if (strlen($value) > $length) {
         if ($with_abbrevs) {
             $value = QuickBooks_Cast::_castAbbreviations($value);
         }
         if (strlen($value) > $length) {
             $value = substr($value, 0, $length);
         }
     }
     return utf8_encode($value);
 }
Beispiel #2
0
 /**
  * Shorten a string to a specific length by truncating or abbreviating the string
  * 
  * QuickBooks often uses unusually short field lengths. This function can 
  * be used to try to make long strings fit cleanly into the QuickBooks 
  * fields. It tries to do a few things:
  * 	- Convert long words to shorter abbreviations
  * 	- Remove non-ASCII characters
  * 	- Truncate the string if it's still too long
  * 
  * @param string $value				The string to shorten
  * @param integer $length			The max. length the string should be
  * @param boolean $with_abbrevs		Whether or not to abbreviate some long words to shorten the string
  * @return string					The shortened string
  */
 protected static function _castTruncate($value, $length, $with_abbrevs = true)
 {
     //$value = QuickBooks_Cast::_castCharset($value);
     if (strlen($value) > $length) {
         if ($with_abbrevs) {
             $value = QuickBooks_Cast::_castAbbreviations($value);
         }
         if (strlen($value) > $length) {
             $value = substr($value, 0, $length);
         }
     }
     // This breaks the UTF8 encoding
     //return utf8_encode($value);
     // Just return the data
     return $value;
 }