ОБСУЖДЕНИЕ

помогите с кодом (код запроса)

2 сообщений1 просмотровОткрыта
#1
всем привет
есть ли в этом коде ошибка
PHP
 
global $kol_zap;
 $zapros=unserialize( trim( @file_get_contents("zapros.php") ) );
$cz=(count($zapros)<$kol_zap)?count($zapros):$kol_zap;
for($i=0;$i<$cz;$i++){
$zapros[$i]=stripslashes($zapros[$i]);
$zapros[$i]=preg_replace('/s+/', ' ', $zapros[$i]);
$zapros2[$i]=str_replace("-"," ", $zapros[$i]);
$zap = trim(change_cyr_register(strtolower($zapros[$i])));
$zap = str_replace(" ","+", $zap);
$zap = str_replace("-","+", $zap);
if(strlen($zapros[$i])<2) continue;
echo <<<GGG

<li><a href="/{$zap}/">{$zapros2[$i]}</a> </li>

GGG;
}
 
?
у меня музыкальный сайт, этот код вроде добавляет последние запросы в zapros.php но иногда записивается название песни или артиста вот так нигина амонкулова (кряко образные символы)
как исправить? буду благодарен
#2
P.S. вот еще код
PHP
 <?php
function change_cyr_register($str='',$to='lower')
{
    $lower = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ь','ы','ъ','э','ю','я');
    $upper = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ь','Ы','Ъ','Э','Ю','Я');
    if($to=='lower') {$pat = &$upper; $rep = &$lower;}
    elseif($to=='upper') {$pat = &$lower; $rep = &$upper;}
    for($n=0; $n<sizeof($pat); ++$n)
    {
        $str = preg_replace("/".$pat[$n]."/",$rep[$n],$str);
    }
    return $str;
}

function filtr($string){
$string = str_replace(array('!','?','^','%','$','#','@',';',':','"','{','}',',','(',')','&','=','_','~','`','<','>','amp','quot','laquo','raquo','«','»','♥','★','ı','♫','♪','vkhp','net','com','ru','org','Ka4Ka','✔','♀','|','¦','®','†','ღ','•','/','[',']','.','*'),' ',trim($string));
$string=str_replace("'","",$string);
$string=preg_replace('/\s+/', ' ', $string);
return $string;
}

function rus2translit($string) {

    $converter = 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, $converter);

}
function rus2translit2($string) {

    $converter = array(

        'a' => 'а',   'b' => 'б',   'v' => 'в',

        'g' => 'г',   'd' => 'д',   'e' => 'е',

        'zh' => 'ж',  'z' => 'з', 'j' =>'дж',

        'i' => 'и',   'y' => 'ий',   'k' => 'к', 'dj' => 'Ди-джей', 'oo' =>'у',

        'l' => 'л',   'm' => 'м',   'n' => 'н',

        'o' => 'о',   'p' => 'п',   'r' => 'р',

        's' => 'с',   't' => 'т',   'u' => 'у',

        'f' => 'ф',   'h' => 'х',   'c' => 'к', 'x' =>'кс', 'ee' => 'и', 'ph' => 'ф',
        'ch' => 'ч',  'sh' => 'ш',  'sch' => 'щ', 'w' => 'в',

       
   'yu' => 'ю',  'ya' => 'я',

        


    );

    return strtr($string, $converter);

}





function query_write($q,$file='zapros.php'){
$armar=array();
$armar=unserialize( trim( @file_get_contents($file) ) );
    if(count($armar)<=1) $armar[3]="TOOL";
@array_unshift($armar, $q);
$armar = @array_unique($armar);
if(count($armar)>50) { $armar=array_chunk($armar, 50);  $armar=$armar[0];}
//print_r($armar);
$fff=fopen($file,w); flock($fff, LOCK_EX);
fputs($fff,serialize($armar) );
flock($fff, LOCK_UN); 
fclose($fff);


}


function Send_Post($post_url, $post_data) 
{ 
//echo $post_url.$post_data;
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_URL, $post_url); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  curl_setopt($ch, CURLOPT_POST, 1); 
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); 
  curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17'); 
    $data = curl_exec($ch); 
  curl_close($ch); 
    return $data; 
} 

function get_lyr($id){
require_once '../cfg.php';
global $api_key;
$api=file_get_contents('http://api.wm-scripts.ru/api.php?method=audio.getLyrics&lyrics_id='.$id.'&key='.$api_key);
$parse=@simplexml_load_string(trim(ltrim($api)));
$text=$parse->lyrics->text;
 return $text;
}


function get_xml_response($q,$offset,$skoka_viv){
global $api_key;
$xml_response = Send_Post(
'http://api.wm-scripts.ru/api.php', 
'count='.$skoka_viv.'&method=audio.search&key='.$api_key.'&offset='.$offset.'&q='.urlencode($q).'');
return $xml_response;
}

function encrypt($pure_string, $encryption_key) {
    $encrypted_string = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $encryption_key, $pure_string, MCRYPT_MODE_CBC, md5($encryption_key));
    return $encrypted_string;
}

function get_song_url($audio) {
global $api_key;
global $api_user_id;
$song_data = urlencode(base64_encode(encrypt($api_user_id.':'.$audio, $api_key)));
$url = "http://api.wm-scripts.ru/api.php?method=audio.getAudioFile&song=".$song_data."&id=".$api_user_id;
return $url;
}

function remote_filesize($url)      
{   
   ob_start();  
   $ch = curl_init($url);   
   curl_setopt($ch, CURLOPT_HEADER, 1);   
   curl_setopt($ch, CURLOPT_NOBODY, 1);   
   $ok = curl_exec($ch);   
   curl_close($ch);   
   $head = ob_get_contents();   
   ob_end_clean();   
   $regex = '/Content-Length:\s([0-9].+?)\s/';   
   $count = preg_match($regex, $head, $matches);   
   return isset($matches[1]) ? $matches[1] : '0';   
}