/** * UTF8::str_ireplace * * @package Kohana * @author Kohana Team * @copyright (c) 2007-2010 Kohana Team * @copyright (c) 2005 Harry Fuecks * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _str_ireplace($search, $replace, $str, & $count = NULL) { if (UTF8::is_ascii($search) AND UTF8::is_ascii($replace) AND UTF8::is_ascii($str)) return str_ireplace($search, $replace, $str, $count); if (is_array($str)) { foreach ($str as $key => $val) { $str[$key] = UTF8::str_ireplace($search, $replace, $val, $count); } return $str; } if (is_array($search)) { $keys = array_keys($search); foreach ($keys as $k) { if (is_array($replace)) { if (array_key_exists($k, $replace)) { $str = UTF8::str_ireplace($search[$k], $replace[$k], $str, $count); } else { $str = UTF8::str_ireplace($search[$k], '', $str, $count); } } else { $str = UTF8::str_ireplace($search[$k], $replace, $str, $count); } } return $str; } $search = UTF8::strtolower($search); $str_lower = UTF8::strtolower($str); $total_matched_strlen = 0; $i = 0; while (preg_match('/(.*?)'.preg_quote($search, '/').'/s', $str_lower, $matches)) { $matched_strlen = strlen($matches[0]); $str_lower = substr($str_lower, $matched_strlen); $offset = $total_matched_strlen + strlen($matches[1]) + ($i * (strlen($replace) - 1)); $str = substr_replace($str, $replace, $offset, strlen($search)); $total_matched_strlen += $matched_strlen; $i++; } $count += $i; return $str; }
public function create_user_meta() { $this->_user_id = $this->unique_key_value($this->_user_email, "user_email"); $rows = $this->_usermeta_rows(); $query = DB::insert("usermeta", $this->_usermeta_columns()); foreach ($rows as $key => &$value) { $rows[$key] = UTF8::str_ireplace(":id", $this->_user_id, $rows[$key]); $rows[$key] = UTF8::str_ireplace(":name", UTF8::ucfirst($this->_display_name), $rows[$key]); $rows[$key] = UTF8::str_ireplace(":level", "0", $rows[$key]); $rows[$key] = UTF8::str_ireplace(":capabilities", "a:1:{s:8:\"customer\";b:1;}", $rows[$key]); $rows[$key] = UTF8::str_ireplace(":billing_first_name", UTF8::get_value($this->_form, "display_name"), $rows[$key]); $rows[$key] = UTF8::str_ireplace(":billing_email", UTF8::get_value($this->_form, "user_email"), $rows[$key]); $rows[$key] = UTF8::str_ireplace(":billing_phone", UTF8::get_value($this->_form, "phone"), $rows[$key]); $query->values($rows[$key]); } //Debug::vars((string) $query); $query->execute(); }
/** * Parsing and formatting data from CBR (cbr.ru) * * @param string $date date formatted as dd.mm.yyyy * @return array */ public function get_currency_from_server($date) { $allow_currency = array('AZN', 'USD', 'EUR', 'AUD', 'JPY', 'GBP', 'BYR', 'LVL', 'TRY', 'UAH', 'EEK'); // 'AUD', 'AZN', 'GBP', 'BYR', 'BGN', 'BRL', 'HUF', 'DKK', 'USD', 'INR', 'KZT', 'CAD', 'KGS', 'CNY', 'LVL', 'LTL', 'MDL', 'NOK', 'PLN', 'RON', 'XDR', 'SGD', 'TJS', 'TRY', 'TMT', 'UZS', 'UAH', 'CZK', 'SEK', 'CHF', 'EEK', 'ZAR', 'KRW', 'JPY' $link = "http://www.cbr.ru/scripts/XML_daily.asp?date_req={$date}"; $text = @file_get_contents($link); $xml = new SimpleXMLElement($text); foreach ($xml->Valute as $exchange) { if (in_array($exchange->CharCode, $allow_currency)) { $currency[] = UTF8::str_ireplace(',', '.', (string) $exchange->Value); } } $AZN = $currency[0]; $RUR = round(1 / $AZN, 4); $USD = round($currency[1] / $AZN, 4); $EUR = $AUD = $JPY = $GBP = $BYR = $LVL = $TRY = $UAH = $EEK = round($currency[2] / $AZN, 4); $AZN = $AZN / $AZN; $rates = array("AZN" => $AZN, "RUR" => $RUR, "USD" => $USD, "EUR" => $EUR, "AUD" => $AUD, "JPY" => $JPY, "GBP" => $GBP, "BYR" => $BYR, "LVL" => $LVL, "TRY" => $TRY, "UAH" => $UAH, "EEK" => $EEK); return $rates; }
/** * Tests UTF8::str_ireplace * * @test * @dataProvider provider_str_ireplace */ public function test_str_ireplace($search, $replace, $subject, $expected) { $this->assertSame($expected, UTF8::str_ireplace($search, $replace, $subject)); }