[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package utf8 4 */ 5 6 //--------------------------------------------------------------- 7 /** 8 * UTF-8 aware alternative to str_ireplace 9 * Case-insensitive version of str_replace 10 * Note: requires utf8_strtolower 11 * Note: it's not fast and gets slower if $search / $replace is array 12 * Notes: it's based on the assumption that the lower and uppercase 13 * versions of a UTF-8 character will have the same length in bytes 14 * which is currently true given the hash table to strtolower 15 * @param string 16 * @return string 17 * @see http://www.php.net/str_ireplace 18 * @see utf8_strtolower 19 * @package utf8 20 */ 21 function utf8_ireplace($search, $replace, $str, $count = NULL){ 22 23 if ( !is_array($search) ) { 24 25 $slen = strlen($search); 26 if ( $slen == 0 ) { 27 return $str; 28 } 29 30 $lendif = strlen($replace) - strlen($search); 31 $search = utf8_strtolower($search); 32 33 $search = preg_quote($search, '/'); 34 $lstr = utf8_strtolower($str); 35 $i = 0; 36 $matched = 0; 37 while ( preg_match('/(.*)'.$search.'/Us',$lstr, $matches) ) { 38 if ( $i === $count ) { 39 break; 40 } 41 $mlen = strlen($matches[0]); 42 $lstr = substr($lstr, $mlen); 43 $str = substr_replace($str, $replace, $matched+strlen($matches[1]), $slen); 44 $matched += $mlen + $lendif; 45 $i++; 46 } 47 return $str; 48 49 } else { 50 51 foreach ( array_keys($search) as $k ) { 52 53 if ( is_array($replace) ) { 54 55 if ( array_key_exists($k,$replace) ) { 56 57 $str = utf8_ireplace($search[$k], $replace[$k], $str, $count); 58 59 } else { 60 61 $str = utf8_ireplace($search[$k], '', $str, $count); 62 63 } 64 65 } else { 66 67 $str = utf8_ireplace($search[$k], $replace, $str, $count); 68 69 } 70 } 71 return $str; 72 73 } 74 75 } 76 77
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |