public static function slug($string, $replacement = '-') { $slug = UTF8::trim(UTF8::strtolower($string)); $map = array('/ä/' => 'ae', '/ö/' => 'oe', '/ü/' => 'ue', '/щ/' => 'sch', '/ш/' => 'sh', '/ч/' => 'ch', '/ц/' => 'c', '/ю/' => 'yu', '/я/' => 'ya', '/ж/' => 'zh', '/а/' => 'a', '/б/' => 'b', '/в/' => 'v', '/г|ґ/' => 'g', '/д/' => 'd', '/е/' => 'e', '/ё/' => 'yo', '/з/' => 'z', '/и|і/' => 'i', '/й/' => 'y', '/к/' => 'k', '/л/' => 'l', '/м/' => 'm', '/н/' => 'n', '/о/' => 'o', '/п/' => 'p', '/р/' => 'r', '/с/' => 's', '/т/' => 't', '/у/' => 'u', '/ф/' => 'f', '/х/' => 'h', '/ы/' => 'y', '/э/' => 'e', '/є/' => 'ye', '/ї/' => 'yi', '/º|°/' => 0, '/¹/' => 1, '/²/' => 2, '/³/' => 3, '/à|á|å|â|ã|ä|ą|ă|ā|ª/' => 'a', '/@/' => 'at', '/æ/' => 'ae', '/ḃ/' => 'b', '/č|ç|¢|ć|ċ|ĉ|©/' => 'c', '/ď|ḋ|đ/' => 'd', '/€/' => 'euro', '/è|é|ê|ě|ẽ|ë|ę|ē|ė|ĕ/' => 'e', '/ƒ|ḟ/' => 'f', '/ģ|ğ|ĝ|ġ/' => 'g', '/ĥ|ħ/' => 'h', '/Ì|Í|Î|Ï/' => 'I', '/ì|í|î|ï|ĩ|ī|į|ı/' => 'i', '/ĵ/' => 'j', '/ķ/' => 'k', '/ł|ľ|ĺ|ļ/' => 'l', '/Ł/' => 'L', '/ṁ/' => 'm', '/ñ|ń|ņ|ň/' => 'n', '/ò|ó|ô|ø|õ|ö|ō|ð|ơ|ő/' => 'o', '/œ/' => 'oe', '/ṗ/' => 'p', '/ř|ŗ|ŕ|®/' => 'r', '/š|ś|ṡ|ş|ș/' => 's', '/ť|ț|ŧ|ţ|ṫ/' => 't', '/þ/' => 'th', '/ß/' => 'ss', '/™/' => 'tm', '/ù|ú|ů|û|ü|ū|ũ|ű|ŭ|ư|ų|µ/' => 'u', '/ẃ|ẅ|ẁ|ŵ/' => 'w', '/×/' => 'x', '/ÿ|ý|ỳ|ŷ|¥/' => 'y', '/Ž|Ż|Ź/' => 'Z', '/ž|ż|ź/' => 'z', '/\\s+/' => $replacement); $slug = preg_replace(array_keys($map), array_values($map), $slug); return URL::title($slug, $replacement); }
/** * Helper for create short description news * * @param string $text * @param integer $limit * @param string $allow_tags * @return string */ public static function short_story($text, $limit = 200, $allow_tags = NULL) { if ($allow_tags != NULL) { $text = strip_tags($text, $allow_tags); } else { $text = strip_tags($text); } $text = str_replace(array('–', ' ', '&', '«', '»', '\\n', '\\r'), ' ', $text); $text = preg_replace('/(\\r\\n|\\n|\\r)\\s*(\\r\\n|\\n|\\r)/', ' ', $text); $text = preg_replace('/(\\r\\n|\\n|\\r)\\s*(\\r\\n|\\n|\\r)/', ' ', $text); $text = preg_replace('/[ \\t]{1,}/', ' ', $text); $text = UTF8::trim($text); if ($limit > 0) { $text = self::limit_chars($text, $limit, NULL, TRUE); // $text = self::limit_words($text, $limit, NULL, TRUE); } // $text = HTML::chars($text); return $text; }
public function SendEmail($post) { $to = $post['to']; if ($to == "") { return; } $from = $post['from']; $subject = $post['subject']; $message = $post['message']; //$transport = Swift_SmtpTransport::newInstance('mail.nnngo.org', 25); $transport = Swift_MailTransport::newInstance(); $transport->start(); $mailer = Swift_Mailer::newInstance($transport); $mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(100)); $message = Swift_Message::newInstance("{$subject}")->setFrom(array("{$from}" => "{$from}"))->setBody("{$message}", 'text/html', 'iso-8859-2'); $message->setReturnPath($post['email']); $message->setSender($from); $message->setPriority(2); $message->setReplyTo($post['email']); $message->addTo(UTF8::trim($to)); if (!$mailer->send($message, $failures)) { echo Kohana::debug($failures); } }
/** * Tests UTF8::trim * * @test * @dataProvider provider_trim */ public function test_trim($input, $input2, $expected) { $this->assertSame($expected, UTF8::trim($input, $input2)); }
/** * Humanize * * Takes multiple words separated by the separator and changes them to spaces * * @param string $str Input string * @param string $separator Input separator * @return string */ function humanize($str, $separator = '_') { return UTF8::ucwords(preg_replace('/[' . preg_quote($separator) . ']+/' . (IS_UTF8_CHARSET && PCRE_UTF8_INSTALLED ? 'u' : ''), ' ', UTF8::trim(UTF8::strtolower($str)))); }
/** * Ensure a parameter is set. * If a parameter is not set, log an error and throw an exception (if * specified). * * @param string the parameter name * @param mixed the parameter value * @param boolean throw an exception? * @return void */ protected function _ensure_parm($name, $value, $throw_exception = TRUE) { if (!isset($value) or is_string($value) and UTF8::trim($value) === '' or $value === array()) { $service = $this->_service; MMI_Log::log_error(__METHOD__, __LINE__, $name . ' not set for ' . $service); if ($throw_exception) { throw new Kohana_Exception(':name not set for :service in :method.', array(':name' => $name, ':service' => $service, ':method' => __METHOD__)); } } }
}, node: { HTMLclass: 'nodeExample1' } }, nodeStructure: { text: { name: "<?php echo $user->name . ' ' . $user->surname; ?> " <?php if (Auth::instance()->get_user()->id == Request::initial()->param('user_id')) { ?> ,desc: { val: 'Добавить родственника', href: '<?php echo Route::url('default', array('controller' => 'user', 'action' => 'relative')); ?> ' } <?php } ?> }, <?php echo UTF8::trim($family_json, '{}'); ?> } }; </script>
/** * Replace runs of multiple whitespace characters with a single space * * @param string $string The string to normalize * * @return string * * @uses UTF8::trim */ public static function normalize_spaces($string) { $normalized = $string; if (!empty($normalized)) { $normalized = preg_replace('/[\\s\\n\\r\\t]+/', ' ', $string); $normalized = UTF8::trim($normalized); } return $normalized; }
/** * Word Limiter, UTF-8 version. * * Limits a string to X number of words. * * @param string * @param int * @param string The end character. Usually an ellipsis * @return string */ function word_limiter($str, $limit = 100, $end_char = '…') { if (UTF8::trim($str) === '') { return $str; } // Added by Ivan Tcholakov, 08-FEB-2016. $end_char = html_entity_decode($end_char, ENT_QUOTES, 'UTF-8'); // preg_match('/^\\s*+(?:\\S++\\s*+){1,' . (int) $limit . '}/' . (IS_UTF8_CHARSET && PCRE_UTF8_INSTALLED ? 'u' : ''), $str, $matches); if (UTF8::strlen($str) === UTF8::strlen($matches[0])) { $end_char = ''; } return UTF8::rtrim($matches[0]) . $end_char; }
/** * Word Limiter, UTF-8 version. * * Limits a string to X number of words. * * @param string * @param int * @param string The end character. Usually an ellipsis * @return string */ function word_limiter($str, $limit = 100, $end_char = '…') { if (UTF8::trim($str) === '') { return $str; } preg_match('/^\\s*+(?:\\S++\\s*+){1,' . (int) $limit . '}/' . (IS_UTF8_CHARSET && PCRE_UTF8_INSTALLED ? 'u' : ''), $str, $matches); if (UTF8::strlen($str) === UTF8::strlen($matches[0])) { $end_char = ''; } return UTF8::rtrim($matches[0]) . $end_char; }