コード例 #1
0
 /**
  * Decorates the given year.
  *
  * @param $year
  * @return string
  */
 protected function decorateYear($year)
 {
     $year = utf8_str_split($year);
     $modifier = '״' . array_pop($year);
     array_push($year, $modifier);
     return implode($year);
 }
コード例 #2
0
ファイル: HebrewNumerology.php プロジェクト: kfirba/hebdate
 /**
  * Get the sum of the word numerical representation.
  *
  * @param      $word
  * @param bool $hebrewYear
  * @return number
  */
 public function sum($word, $hebrewYear = false)
 {
     $this->validateHebrewCharactersOnly($word);
     $letters = utf8_str_split($word);
     $letters[0] = $letters[0] == 'ה' && $hebrewYear ? 5000 : $letters[0];
     return array_sum(array_map(function ($letter) {
         return is_numeric($letter) ? $letter : self::numerology[$letter];
     }, $letters));
 }
コード例 #3
0
ファイル: validate.php プロジェクト: arturslukins/rvt
function CheckUpperLetters($st)
{
    $lv = "AĀBCČDEĒFGĢHIĪJKĶLĻMNŅOPRSŠTUŪVZŽ";
    $arr1 = utf8_str_split($st);
    $let = $arr1[0];
    // 1 burts
    $arr2 = utf8_str_split($lv);
    // char of latvian upper letters
    for ($i = 0; $i < strlen($lv) - 1; $i++) {
        if ($let == $arr2[$i]) {
            return TRUE;
        }
    }
    return FALSE;
}
コード例 #4
0
ファイル: string.php プロジェクト: nogsus/joomla-platform
 /**
  * UTF-8 aware alternative to str_split
  * Convert a string to an array
  *
  * @param   string   $str        UTF-8 encoded string to process
  * @param   integer  $split_len  Number to characters to split string by
  *
  * @return  array
  *
  * @see     http://www.php.net/str_split
  * @since   11.1
  */
 public static function str_split($str, $split_len = 1)
 {
     jimport('phputf8.str_split');
     return utf8_str_split($str, $split_len);
 }
コード例 #5
0
ファイル: functions_messenger.php プロジェクト: jvinhit/php
/**
* Encodes the given string for proper display in UTF-8.
*
* This version is using base64 encoded data. The downside of this
* is if the mail client does not understand this encoding the user
* is basically doomed with an unreadable subject.
*
* Please note that this version fully supports RFC 2045 section 6.8.
*/
function mail_encode($str)
{
    // define start delimimter, end delimiter and spacer
    $start = "=?UTF-8?B?";
    $end = "?=";
    $spacer = $end . ' ' . $start;
    $split_length = 64;
    $encoded_str = base64_encode($str);
    // If encoded string meets the limits, we just return with the correct data.
    if (strlen($encoded_str) <= $split_length) {
        return $start . $encoded_str . $end;
    }
    // If there is only ASCII data, we just return what we want, correctly splitting the lines.
    if (strlen($str) === utf8_strlen($str)) {
        return $start . implode($spacer, str_split($encoded_str, $split_length)) . $end;
    }
    // UTF-8 data, compose encoded lines
    $array = utf8_str_split($str);
    $str = '';
    while (sizeof($array)) {
        $text = '';
        while (sizeof($array) && intval((strlen($text . $array[0]) + 2) / 3) << 2 <= $split_length) {
            $text .= array_shift($array);
        }
        $str .= $start . base64_encode($text) . $end . ' ';
    }
    return substr($str, 0, -1);
}
コード例 #6
0
/**
* Truncates string while retaining special characters if going over the max length
* The default max length is 60 at the moment
* The maximum storage length is there to fit the string within the given length. The string may be further truncated due to html entities.
* For example: string given is 'a "quote"' (length: 9), would be a stored as 'a &quot;quote&quot;' (length: 19)
*
* @param string $string The text to truncate to the given length. String is specialchared.
* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char)
* @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars).
* @param bool $allow_reply Allow Re: in front of string
* 	NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_length) and is deprecated.
* @param string $append String to be appended
*/
function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '')
{
    $chars = array();
    $strip_reply = false;
    $stripped = false;
    if ($allow_reply && strpos($string, 'Re: ') === 0) {
        $strip_reply = true;
        $string = substr($string, 4);
    }
    $_chars = utf8_str_split(htmlspecialchars_decode($string));
    $chars = array_map('utf8_htmlspecialchars', $_chars);
    // Now check the length ;)
    if (sizeof($chars) > $max_length) {
        // Cut off the last elements from the array
        $string = implode('', array_slice($chars, 0, $max_length - utf8_strlen($append)));
        $stripped = true;
    }
    // Due to specialchars, we may not be able to store the string...
    if (utf8_strlen($string) > $max_store_length) {
        // let's split again, we do not want half-baked strings where entities are split
        $_chars = utf8_str_split(htmlspecialchars_decode($string));
        $chars = array_map('utf8_htmlspecialchars', $_chars);
        do {
            array_pop($chars);
            $string = implode('', $chars);
        } while (!empty($chars) && utf8_strlen($string) > $max_store_length);
    }
    if ($strip_reply) {
        $string = 'Re: ' . $string;
    }
    if ($append != '' && $stripped) {
        $string = $string . $append;
    }
    return $string;
}
コード例 #7
0
 /**
  * Generate the captcha question
  *
  * @return string The question string
  */
 protected function getQuestion()
 {
     $int1 = rand(1, 9);
     $int2 = rand(1, 9);
     $question = $GLOBALS['TL_LANG']['SEC']['question' . rand(1, 3)];
     $question = sprintf($question, $int1, $int2);
     $this->Session->set('captcha_' . $this->strId, array('sum' => $int1 + $int2, 'key' => $this->strCaptchaKey, 'time' => time()));
     $strEncoded = '';
     $arrCharacters = utf8_str_split($question);
     foreach ($arrCharacters as $strCharacter) {
         $strEncoded .= sprintf('&#%s;', utf8_ord($strCharacter));
     }
     return $strEncoded;
 }
コード例 #8
0
/**
* Encodes the given string for proper display in UTF-8.
*
* This version is using base64 encoded data. The downside of this
* is if the mail client does not understand this encoding the user
* is basically doomed with an unreadable subject.
*
* Please note that this version fully supports RFC 2045 section 6.8.
*
* @param string $eol End of line we are using (optional to be backwards compatible)
*/
function mail_encode($str, $eol = "\r\n")
{
    // define start delimimter, end delimiter and spacer
    $start = "=?UTF-8?B?";
    $end = "?=";
    $delimiter = "{$eol} ";
    // Maximum length is 75. $split_length *must* be a multiple of 4, but <= 75 - strlen($start . $delimiter . $end)!!!
    $split_length = 60;
    $encoded_str = base64_encode($str);
    // If encoded string meets the limits, we just return with the correct data.
    if (strlen($encoded_str) <= $split_length) {
        return $start . $encoded_str . $end;
    }
    // If there is only ASCII data, we just return what we want, correctly splitting the lines.
    if (strlen($str) === utf8_strlen($str)) {
        return $start . implode($end . $delimiter . $start, str_split($encoded_str, $split_length)) . $end;
    }
    // UTF-8 data, compose encoded lines
    $array = utf8_str_split($str);
    $str = '';
    while (sizeof($array)) {
        $text = '';
        while (sizeof($array) && intval((strlen($text . $array[0]) + 2) / 3) << 2 <= $split_length) {
            $text .= array_shift($array);
        }
        $str .= $start . base64_encode($text) . $end . $delimiter;
    }
    return substr($str, 0, -strlen($delimiter));
}
コード例 #9
0
 /**
  * UTF-8 aware alternative to str_split
  * Convert a string to an array
  *
  * @param   string   $str        UTF-8 encoded string to process
  * @param   integer  $split_len  Number to characters to split string by
  *
  * @return  array
  *
  * @see     http://www.php.net/str_split
  * @since   2.0
  */
 public static function str_split($str, $split_len = 1)
 {
     if (!function_exists('utf8_str_split')) {
         require_once __DIR__ . '/phputf8/str_split.php';
     }
     return utf8_str_split($str, $split_len);
 }
コード例 #10
0
 function testSplitNewline()
 {
     $str = "Iñtërn\nâtiônàl\nizætiøn\n";
     $array = array('I', 'ñ', 't', 'ë', 'r', 'n', "\n", 'â', 't', 'i', 'ô', 'n', 'à', 'l', "\n", 'i', 'z', 'æ', 't', 'i', 'ø', 'n', "\n");
     $this->assertEqual(utf8_str_split($str), $array);
 }
コード例 #11
0
 /**
  * UTF-8 aware alternative to str_split
  * Convert a string to an array
  *
  * @param   string   $str        UTF-8 encoded string to process
  * @param   integer  $split_len  Number to characters to split string by
  *
  * @return  array
  *
  * @see     http://www.php.net/str_split
  * @since   1.0
  */
 public static function str_split($str, $split_len = 1)
 {
     require_once __DIR__ . '/phputf8/str_split.php';
     return utf8_str_split($str, $split_len);
 }
コード例 #12
0
 /**
  * UTF-8 aware alternative to str_split()
  *
  * Convert a string to an array.
  *
  * @param   string   $str        UTF-8 encoded string to process
  * @param   integer  $split_len  Number to characters to split string by
  *
  * @return  array
  *
  * @see     http://www.php.net/str_split
  * @since   1.3.0
  */
 public static function str_split($str, $split_len = 1)
 {
     return utf8_str_split($str, $split_len);
 }
コード例 #13
0
ファイル: StringUtil.php プロジェクト: eknoes/core
 /**
  * Encode all e-mail addresses within a string
  *
  * @param string $strString The string to encode
  *
  * @return string The encoded string
  */
 public static function encodeEmail($strString)
 {
     $arrEmails = array();
     preg_match_all('/\\w([-.+!#$%&\'*\\/=?^`{}|~\\w]*\\w)?@\\w([-.\\w]*\\w)?\\.\\w{2,63}/u', $strString, $arrEmails);
     foreach ((array) $arrEmails[0] as $strEmail) {
         $strEncoded = '';
         $arrCharacters = utf8_str_split($strEmail);
         foreach ($arrCharacters as $strCharacter) {
             $strEncoded .= sprintf(rand(0, 1) ? '&#x%X;' : '&#%s;', utf8_ord($strCharacter));
         }
         $strString = str_replace($strEmail, $strEncoded, $strString);
     }
     return str_replace('mailto:', '&#109;&#97;&#105;&#108;&#116;&#111;&#58;', $strString);
 }