public function truncate($config = array()) { $config = new KConfig($config); $config->append(array('text' => '', 'offset' => 0, 'length' => 100, 'pad' => ' ...')); // Don't show endstring if actual string length is less than cutting length $config->endstr = KHelperString::strlen($config->text) < $config->length ? '' : $config->pad; return KHelperString::substr(strip_tags($config->text), $config->offset, $config->length) . $config->pad; }
public function truncate($config = array()) { $config = new KConfig($config); $config->append(array('text' => '', 'offset' => 0, 'length' => 100, 'path' => ' ...', 'allowed_tags' => '')); $text = strip_tags($config->text, $config->allowed_tags); if (KHelperString::strlen($config->text) > $config->length) { $text = KHelperString::substr($text, $config->offset, $config->length) . $config->path; } return $text; }
/** * UTF-8 aware alternative to strspn * * Find length of initial segment matching mask * * @param string the haystack * @param string the mask * @param int start optional * @param int length optional * @see http://www.php.net/strspn */ public static function strspn($str, $mask, $start = NULL, $length = NULL) { $mask = preg_replace('!([\\\\\\-\\]\\[/^])!', '\\\\${1}', $mask); if ($start !== NULL || $length !== NULL) { $str = KHelperString::substr($str, $start, $length); } preg_match('/^[' . $mask . ']+/u', $str, $matches); if (isset($matches[0])) { return KHelperString::strlen($matches[0]); } return 0; }
/** * Instantiate a Merchant_Billing_CreditCard object * * @param KConfig $data * @return Merchant_Billing_CreditCard */ protected function _instantiateCreditCard($data) { if ($data->token) { unset($data['creditcard']); unset($data['contact']); return; } $data->append(array('creditcard' => new KConfig())); $creditcard = $data->creditcard; $name = trim($creditcard->name); $space = KHelperString::strpos($name, ' '); $creditcard_data = array('type' => $creditcard->type, "first_name" => KHelperString::ucwords(KHelperString::substr($name, 0, $space)), "last_name" => KHelperString::ucwords(KHelperString::substr($name, $space + 1)), "number" => $creditcard->number, "month" => $creditcard->month, "year" => $creditcard->year, "verification_value" => $creditcard->csv); $creditcard = new Merchant_Billing_CreditCard($creditcard_data); $this->creditcard = $creditcard; $contact = $this->_instantiateContact($data); $this->order->setPaymentMethod(new ComSubscriptionsDomainPaymentMethodCreditcard($creditcard, $contact)); return $creditcard; }
/** * returns substring of characters around a searchword. * * @param string The source string * @param int Number of chars to return * @param string The searchword to select around * * @return string */ public function substring($text, $searchword, $length = 200) { $textlen = KHelperString::strlen($text); $lsearchword = KHelperString::strtolower($searchword); $wordfound = false; $pos = 0; while ($wordfound === false && $pos < $textlen) { if (($wordpos = @KHelperString::strpos($text, ' ', $pos + $length)) !== false) { $chunk_size = $wordpos - $pos; } else { $chunk_size = $length; } $chunk = KHelperString::substr($text, $pos, $chunk_size); $wordfound = KHelperString::strpos(KHelperString::strtolower($chunk), $lsearchword); if ($wordfound === false) { $pos += $chunk_size + 1; } } //while if ($wordfound !== false) { return ($pos > 0 ? '... ' : '') . $chunk . ' ...'; } else { if (($wordpos = @KHelperString::strpos($text, ' ', $length)) !== false) { return KHelperString::substr($text, 0, $wordpos) . ' ...'; } else { return KHelperString::substr($text, 0, $length); } } }