<script>document.addEventListener("DOMContentLoaded", function() {
var input = document.querySelector(".maskphone");
input.addEventListener("input", mask);
input.addEventListener("focus", mask);
input.addEventListener("blur", mask);
/***/
function mask(event) {
var blank = "+_ (___) ___-__-__";
var i = 0;
var val = this.value.replace(/\D/g, "").replace(/^8/, "7"); // <---
this.value = blank.replace(/./g, function(char) {
if (/[_\d]/.test(char) && i < val.length) return val.charAt(i++);
return i >= val.length ? "" : char;
});
if (event.type == "blur") {
if (this.value.length == 2) this.value = "";
} else {
setCursorPosition(this, this.value.length);
}
};
/***/
function setCursorPosition(elem, pos) {
elem.focus();
if (elem.setSelectionRange) {
elem.setSelectionRange(pos, pos);
return;
}
if (elem.createTextRange) {
var range = elem.createTextRange();
range.collapse(true);
range.moveEnd("character", pos);
range.moveStart("character", pos);
range.select();
return;
}
}
});
</script>
<input class="maskphone">
// Шаг 1
$arr = [];
if (!empty($result->SearchResult->PartsList)) {
foreach ($result->SearchResult->PartsList as $key=>$value) {
if(is_array($result->SearchResult->PartsList->Part)) {
foreach ($value as $k1=>$v1) {
$arr['ROSSKO'][$k1]['name'] = $v1->name;
$arr['ROSSKO'][$k1]['partnumber'] = $v1->partnumber;
$arr['ROSSKO'][$k1]['brand'] = $v1->brand;
$arr['ROSSKO'][$k1]['guid'] = $v1->guid;
if (isset($v1->stocks)) {
$arr['ROSSKO'][$k1]['stocks'] = $v1->stocks;
}
/*
if (isset($v1->crosses)) {
$arr['ROSSKO'][$k1]['crosses'] = $v1->crosses;
}
*/
}
}
else {
$arr['ROSSKO'][0]['name'] = $value->name;
$arr['ROSSKO'][0]['partnumber'] = $value->partnumber;
$arr['ROSSKO'][0]['brand'] = $value->brand;
$arr['ROSSKO'][0]['guid'] = $value->guid;
if (isset($value->stocks)) {
$arr['ROSSKO'][0]['stocks'] = $value->stocks;
}
/*
if (isset($value->crosess)) {
$arr['ROSSKO'][0]['crosess'] = $value->crosess;
}
*/
}
}
}
// Шаг 2
$arr2 = [];
foreach ($arr['ROSSKO'] as $key=>$value) {
$arr2['ROSSKO'][$key]['name'] = $value['name'];
$arr2['ROSSKO'][$key]['partnumber'] = $value['partnumber'];
$arr2['ROSSKO'][$key]['brand'] = $value['brand'];
$arr2['ROSSKO'][$key]['guid'] = $value['guid'];
if (isset($value['stocks']->stock)) {
if (is_array($value['stocks']->stock)) {
foreach ($value['stocks']->stock as $k3=>$v3) {
$arr2['ROSSKO'][$key]['stocks']['stock'][$k3]['id'] = $v3->id;
$arr2['ROSSKO'][$key]['stocks']['stock'][$k3]['price'] = $v3->price;
$arr2['ROSSKO'][$key]['stocks']['stock'][$k3]['count'] = $v3->count;
$arr2['ROSSKO'][$key]['stocks']['stock'][$k3]['description'] = $v3->description;
}
}
else {
$arr2['ROSSKO'][$key]['stocks']['stock'][0]['id'] = $value['stocks']->stock->id;
$arr2['ROSSKO'][$key]['stocks']['stock'][0]['price'] = $value['stocks']->stock->price;
$arr2['ROSSKO'][$key]['stocks']['stock'][0]['count'] = $value['stocks']->stock->price;
$arr2['ROSSKO'][$key]['stocks']['stock'][0]['description'] = $value['stocks']->stock->price;
}
}
}
return $arr2;
public function assembly() {
function translit($string)
{
$conv = array(
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e',
'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'y', 'к' => 'k',
'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r',
'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c',
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch', 'ь' => '', 'ы' => 'y', 'ъ' => '',
'э' => 'e', 'ю' => 'yu', 'я' => 'ya', 'А' => 'A', 'Б' => 'B', 'В' => 'V',
'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z',
'И' => 'I', 'Й' => 'Y', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N',
'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U',
'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch',
'Ь' => '', 'Ы' => 'Y', 'Ъ' => '', 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya',
); // вероятно, придется дополнять или исправлять для других алфавитов
return strtr($string, $conv);
}
$files = glob('data/arrays/*_result.json');
$result = array();
foreach($files as $file)
{
$bm_name = ucfirst(basename($file, '_result.json'));
$json = json_decode(file_get_contents($file), TRUE);
foreach($json as $arr)
{
$symbol = sprintf('%s-%s', soundex(translit($arr['Home'])), soundex(translit($arr['Away'])));
$result[$symbol][$bm_name] = $arr;
}
}
//print_r($result);
$new_result = array();
foreach($result as $symbol => $bms)
{
if(count($bms) > 1)
{
$new_result[] = $bms;
// echo $symbol.'<br>';
// print_r($bms);
}
}
print_r($new_result);
echo '<br>from '.count($result).' $result';
}