Exemplo n.º 1
0
 /**
  * @covers Patchwork\Utf8::str_split
  */
 function testStr_split()
 {
     $this->assertSame(array('d', 'é', 'j', 'à'), u::str_split('déjà', 1));
     $this->assertSame(array('dé', 'jà'), u::str_split('déjà', 2));
 }
Exemplo n.º 2
0
 /**
  * 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)
 {
     foreach (static::extractEmail($strString) 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:', 'mailto:', $strString);
 }
/**
 * Converts a string to an array.
 * @param string $string				The input string.
 * @param int $split_length				Maximum character-length of the chunk, one character by default.
 * @param string $encoding (optional)	The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
 * @return array						The result array of chunks with the spcified length.
 * Notes:
 * If the optional split_length parameter is specified, the returned array will be broken down into chunks
 * with each being split_length in length, otherwise each chunk will be one character in length.
 * FALSE is returned if split_length is less than 1.
 * If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array element.
 * This function is aimed at replacing the function str_split() for human-language strings.
 * @link http://php.net/str_split
 */
function api_str_split($string, $split_length = 1, $encoding = null)
{
    return Utf8::str_split($string, $split_length);
}
Exemplo n.º 4
0
/**
 * Convert a string to an array
 *
 * @param string $str
 *
 * @return array
 *
 * @deprecated Deprecated since Contao 4.0, to be removed in Contao 5.0.
 *             Use Patchwork\Utf8::str_split() instead.
 */
function utf8_str_split($str)
{
    @trigger_error('Using utf8_str_split() has been deprecated and will no longer work in Contao 5.0. Use Patchwork\\Utf8::str_split() instead.', E_USER_DEPRECATED);
    return Utf8::str_split($str);
}
 public function test_split_newline()
 {
     $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->assertEquals($array, u::str_split($str));
 }
Exemplo n.º 6
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);
     /** @var SessionInterface $objSession */
     $objSession = \System::getContainer()->get('session');
     $objSession->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;
 }
Exemplo n.º 7
0
 /**
  * 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)
 {
     if (strpos($strString, '@') === false) {
         return $strString;
     }
     $arrEmails = static::extractEmail($strString, \Config::get('allowedTags'));
     foreach ($arrEmails 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:', 'mailto:', $strString);
 }