Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/utf/utf_tools.php

    r400 r702  
    33*
    44* @package utf
    5 * @version $Id: utf_tools.php 8510 2008-04-20 05:16:42Z davidmj $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    7171                $len = strlen($str);
    7272                $ret = '';
    73        
     73
    7474                while ($pos < $len)
    7575                {
     
    253253                {
    254254                        $ar     = explode($needle, $str);
    255                        
     255
    256256                        if (sizeof($ar) > 1)
    257257                        {
     
    528528                }
    529529                else
    530                 {       
     530                {
    531531                        // offset == 0; just anchor the pattern
    532532                        $op = '^';
     
    561561                                $lx = (int) ($length / 65535);
    562562                                $ly = $length % 65535;
    563                                
     563
    564564                                // negative length requires a captured group
    565565                                // of length characters
     
    633633                return array($str);
    634634        }
    635        
     635
    636636        preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar);
    637637        return $ar[0];
     
    19181918}
    19191919
     1920/**
     1921* UTF8-safe basename() function
     1922*
     1923* basename() has some limitations and is dependent on the locale setting
     1924* according to the PHP manual. Therefore we provide our own locale independant
     1925* basename function.
     1926*
     1927* @param string $filename The filename basename() should be applied to
     1928* @return string The basenamed filename
     1929*/
     1930function utf8_basename($filename)
     1931{
     1932        // We always check for forward slash AND backward slash
     1933        // because they could be mixed or "sneaked" in. ;)
     1934        // You know, never trust user input...
     1935        if (strpos($filename, '/') !== false)
     1936        {
     1937                $filename = utf8_substr($filename, utf8_strrpos($filename, '/') + 1);
     1938        }
     1939
     1940        if (strpos($filename, '\\') !== false)
     1941        {
     1942                $filename = utf8_substr($filename, utf8_strrpos($filename, '\\') + 1);
     1943        }
     1944
     1945        return $filename;
     1946}
     1947
     1948/**
     1949* UTF8-safe str_replace() function
     1950*
     1951* @param string $search The value to search for
     1952* @param string $replace The replacement string
     1953* @param string $subject The target string
     1954* @return string The resultant string
     1955*/
     1956function utf8_str_replace($search, $replace, $subject)
     1957{
     1958        if (!is_array($search))
     1959        {
     1960                $search = array($search);
     1961                if (is_array($replace))
     1962                {
     1963                        $replace = (string) $replace;
     1964                        trigger_error('Array to string conversion', E_USER_NOTICE);
     1965                }
     1966        }
     1967
     1968        $length = sizeof($search);
     1969
     1970        if (!is_array($replace))
     1971        {
     1972                $replace = array_fill(0, $length, $replace);
     1973        }
     1974        else
     1975        {
     1976                $replace = array_pad($replace, $length, '');
     1977        }
     1978
     1979        for ($i = 0; $i < $length; $i++)
     1980        {
     1981                $search_length = utf8_strlen($search[$i]);
     1982                $replace_length = utf8_strlen($replace[$i]);
     1983
     1984                $offset = 0;
     1985                while (($start = utf8_strpos($subject, $search[$i], $offset)) !== false)
     1986                {
     1987                        $subject = utf8_substr($subject, 0, $start) . $replace[$i] . utf8_substr($subject, $start + $search_length);
     1988                        $offset = $start + $replace_length;
     1989                }
     1990        }
     1991
     1992        return $subject;
     1993}
     1994
    19201995?>
Note: See TracChangeset for help on using the changeset viewer.