Tell me please, comrades. I come to some page with the query of the form index.php?gost=ГОСТ%C2%A0Р%C2%A050571.5.51−2013 here's the code

 $query = $_GET['gost']; echo '<meta charset="utf-8">'; echo '1 '.$query.'<br>'; // ВИЖУ $query = preg_replace('/[\x00-\x1F\x7F\xA0]/u', ' ', $query); echo '2 '.$query.'<br>'; // ВИЖУ $query = preg_replace('/\s+/','%',$query); $query = iconv('UTF-8', 'windows-1251', $query); echo '3 '.$query; // ПУСТО 

Item 3 is empty.

However, if I come with the query index.php?gost=ГОСТ%C2%A0Р%20ИСО/МЭК%2074981-99 , then all 3 items are displayed normally.

    1 answer 1

    You have a dash character encoded somehow crooked in the first case. It has an ASCII code different from 2D

    • strtr is better in this case than preg_replace. - Gnyava Ya
    • Yeah, and str_replace even better. - And