$template = file_get_contents('templates/output_start.htm') . file_get_contents('templates/hypnomap.htm') . file_get_contents('templates/output_end.htm'); //echo $template; $patient = $_SESSION['patient']; //print_r($patient); //Проверка - Салем или нет if (strtolower($patient['city']) == 'salem') { $template = str_replace(array('{ifsalem}', '{endifsalem}'), array('', ''), $template); } else { $template = preg_replace('~\\{ifsalem\\}.*?\\{endifsalem\\}~', '', $template); } $repl = array('character_name' => $_SESSION['patient']['character_name'], 'cityname' => $cities[strtolower($patient['city'])]); $tmpl = $year == '1945' ? 'location_1945.htm' : 'location.htm'; $location_stub = file_get_contents('templates/' . $tmpl); foreach ($mapping[strtolower($patient['city'])] as $item) { $rus_loc = $locations[$item]; $rus_loc = tools::cyr2utf(mb_strtolower(tools::utf2cyr($rus_loc))); if (!$item || mb_strpos($patient['locs_absent'], $rus_loc) !== false) { $txt = "\n\t\t<div class=location></div>\n"; } else { $txt = $location_stub; foreach (array('location' => $item, 'location_name' => $locations[$item], 'trigger_word' => $trigger_pages[$patient['psychotype']][$item], 'trigger_page' => 'common/' . $trigger_pages['trigger_page'][$item]) as $k => $v) { $txt = str_replace('{' . $k . '}', $v, $txt); } } $loc_text .= $txt; } $repl['locations'] = $loc_text; foreach ($repl as $k => $v) { $template = str_replace('{' . $k . '}', $v, $template); } echo $template;
public static function read_csv($filename, $assoc_field = '', $needed_fields = array(), $use_ciphered = false) { $tempfile = '~tmp.dat'; if ($use_ciphered) { $ciphered_file = str_replace('.csv', '.dat', $filename); if (file_exists($filename)) { file_put_contents($ciphered_file, base64_encode(file_get_contents($filename))); } $text = file_get_contents($ciphered_file); file_put_contents($tempfile, base64_decode($text)); $f = fopen($tempfile, 'r'); } else { $f = fopen($filename, 'r'); } while ($row = fgetcsv($f, 0, ';')) { $row = tools::cyr2utf($row); if (!isset($fields)) { $fields = $row; $last = array_search('—', $fields); if ($last) { $fields = array_splice($fields, 0, $last); } } else { $row = array_splice($row, 0, count($fields)); if ($row) { while (count($row) < count($fields)) { $row[] = ''; } // Делаем ассоциативный массив по полям $arr = array_combine($fields, $row); // Оставляем только нужные поля if ($needed_fields) { foreach ($arr as $key => $val) { if (!in_array($key, $needed_fields)) { unset($arr[$key]); } } } if ($assoc_field) { $out[strtolower($arr[$assoc_field])] = $arr; } else { $out[] = $arr; } } } } if (file_exists($tempfile)) { @unlink($tempfile); } return $out; }