Changeset 702 for trunk/forum/includes/utf/utf_tools.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/utf/utf_tools.php
r400 r702 3 3 * 4 4 * @package utf 5 * @version $Id : utf_tools.php 8510 2008-04-20 05:16:42Z davidmj$5 * @version $Id$ 6 6 * @copyright (c) 2006 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 71 71 $len = strlen($str); 72 72 $ret = ''; 73 73 74 74 while ($pos < $len) 75 75 { … … 253 253 { 254 254 $ar = explode($needle, $str); 255 255 256 256 if (sizeof($ar) > 1) 257 257 { … … 528 528 } 529 529 else 530 { 530 { 531 531 // offset == 0; just anchor the pattern 532 532 $op = '^'; … … 561 561 $lx = (int) ($length / 65535); 562 562 $ly = $length % 65535; 563 563 564 564 // negative length requires a captured group 565 565 // of length characters … … 633 633 return array($str); 634 634 } 635 635 636 636 preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar); 637 637 return $ar[0]; … … 1918 1918 } 1919 1919 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 */ 1930 function 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 */ 1956 function 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 1920 1995 ?>
Note:
See TracChangeset
for help on using the changeset viewer.