示例#1
0
/**
 * UTF8::strrpos
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2012 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strrpos($str, $search, $offset = 0)
{
    $offset = (int) $offset;
    if (UTF8::is_ascii($str) and UTF8::is_ascii($search)) {
        return strrpos($str, $search, $offset);
    }
    if ($offset == 0) {
        $array = explode($search, $str, -1);
        return isset($array[0]) ? UTF8::strlen(implode($search, $array)) : FALSE;
    }
    $str = UTF8::substr($str, $offset);
    $pos = UTF8::strrpos($str, $search);
    return $pos === FALSE ? FALSE : $pos + $offset;
}
示例#2
0
文件: UTF8Test.php 项目: azuya/Wi3
 /**
  * Tests UTF8::strrpos
  *
  * @test
  * @dataProvider provider_strrpos
  */
 public function test_strrpos($input, $str, $offset, $expected)
 {
     $this->assertSame($expected, UTF8::strrpos($input, $str, $offset));
     UTF8::$server_utf8 = !UTF8::$server_utf8;
     $this->assertSame($expected, UTF8::strrpos($input, $str, $offset));
     UTF8::$server_utf8 = !UTF8::$server_utf8;
 }
示例#3
0
 /**
  * Finds position of last occurrence of a char in a UTF-8 string. This is
  * a UTF8-aware version of [strrpos](http://php.net/strrpos).
  *
  * $position = UTF8::strrpos($str, $search);
  *
  * @author  Harry Fuecks <*****@*****.**>
  * @param   string   haystack
  * @param   string   needle
  * @param   integer  offset from which character in haystack to start searching
  * @return  integer  position of needle
  * @return  boolean  FALSE if the needle is not found
  * @uses	IS_MBSTRING
  */
 public static function strrpos($str, $search, $offset = 0)
 {
     $offset = (int) $offset;
     if (IS_MBSTRING) {
         return mb_strrpos($str, $search, $offset, Core::$charset);
     }
     if (UTF8::is_ascii($str) and UTF8::is_ascii($search)) {
         return strrpos($str, $search, $offset);
     }
     if ($offset == 0) {
         $array = explode($search, $str, -1);
         return isset($array[0]) ? UTF8::strlen(implode($search, $array)) : FALSE;
     }
     $str = UTF8::substr($str, $offset);
     $pos = UTF8::strrpos($str, $search);
     return $pos === FALSE ? FALSE : $pos + $offset;
 }
示例#4
0
 /**
  * Tests UTF8::strrpos
  *
  * @test
  * @dataProvider provider_strrpos
  */
 public function test_strrpos($input, $str, $offset, $expected)
 {
     $this->assertSame($expected, UTF8::strrpos($input, $str, $offset));
 }