$file_url = 'test.txt';
$text = file_get_contents($file_url);
$words = preg_split('/\s+/', $text);
$words = array_count_values($words);
arsort($words);
$nums = array_unique(array_values($words));
$res = array();
foreach ($nums as $num) {
$num_words = array_keys($words, $num);
asort($num_words);
foreach($num_words as $num_word) {
$res[$num_word] = $num;
}
}
var_dump($res);
<?php
if ( !checkAccess() ) {
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
die("<h1>404</h1>Not found");
}
function checkAccess()
{
$ip = getIP();
return isAllowedIP($ip);
}
function isAllowedIP($ip)
{
$allowed_countries = array("RU", "UA", "BY", "KZ"); //разрешённые страны
$ip_info = getIPInfo($ip);
return ( in_array($ip_info["countryCode"], $allowed_countries) || in_array($ip_info["country"], $allowed_countries) );
}
function getIPInfo($ip)
{
$json = file_get_contents("http://ip-api.com/json/".$ip);
return json_decode($json, true);
}
function getIP()
{
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
return $_SERVER["HTTP_CLIENT_IP"];
} else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
return $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
return $_SERVER["REMOTE_ADDR"];
}
}
login | state | name | age
------------------------------------------------
vasya | new | NULL | NULL
petya | waiting_for_name | NULL | NULL
vanya | waiting_for_age | Иван | NULL
misha | all_data_given | Михаил | 46
if ($current_user_state == 'new') {
echo 'What\'s your name?';
setCurrentUserState('waiting_for_name');
} else if ($current_user_state == 'waiting_for_name') {
echo 'Hello, ' . $user_message . '!';
setCurrentUserState('waiting_for_age');
} else if ($current_user_state == 'waiting_for_age') {
echo 'Oh, you are ' . $user_message . '! You\'re so damn old';
setCurrentUserState('all_data_given');
}
<script type='text/javascript'>
<?php
$arr = Array ( [0] => 1305 [1] => 1306 [2] => 1307 );
echo "var pr = " . json_encode($arr) . ";";
?>
</script>