T
T
teplenev2011-11-09 08:23:49
PHP
teplenev, 2011-11-09 08:23:49

Encoding flies when page jumps through php?

Actually I'm trying to get a page from professionali.ru, I get rubbish like "ёСЏ РђР"ександр Захаров РњРѕСЃРєРІР°, Р РѕСЃСЃРёСЏ Дмитрий Щел
РєРѓРѓ

&lt;?php<br/>
echo &quot;Сдираем первые 10 страниц с Профессионалов&quot;;<br/>
include 'strip_tags_smart.php';<br/>
for ($x=0; $x&lt;2; $x++) {<br/>
 $page = file_get_contents ( 'http://www.professionali.ru/~'.$x);<br/>
 iconv(&quot;UTF-8&quot;, &quot;Windows-1251&quot;, $page);<br/>
 $page = strip_tags ($page);<br/>
 $page = strip_tags_smart( stripslashes($page));<br/>
 echo $page.&quot;<hr/>&quot;;<br/>
};<br/>
<br/>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Firsov, 2011-11-10
@teplenev

$page = iconv("UTF-8", "Windows-1251", $page);

A
Anatoly Egorov, 2011-11-09
@alxrt

This happens because the site from which the download occurs is cp1251 encoding, and the conversion function is used incorrectly - the arguments are mixed up.
Quote from php.net:
string iconv ( string $in_charset , string $out_charset , string $str )
Your source encoding is UTF-8, and the resulting encoding is cp1251. Need the opposite.

H
homm, 2011-11-09
@homm

This is because iconv returns a new string as the result, rather than modifying the original. And you ignore it (the result).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question