<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mihalytch personal blog &#187; кодировка</title>
	<atom:link href="http://mihalytch.org.ua/tag/kodirovka/feed" rel="self" type="application/rss+xml" />
	<link>http://mihalytch.org.ua</link>
	<description>Все о высоких технологиях</description>
	<lastBuildDate>Thu, 20 May 2010 07:56:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Перекодировка UTF-8 в cp1251</title>
		<link>http://mihalytch.org.ua/programming/php/convert-utf8-cp1251.html</link>
		<comments>http://mihalytch.org.ua/programming/php/convert-utf8-cp1251.html#comments</comments>
		<pubDate>Tue, 26 Feb 2008 15:54:55 +0000</pubDate>
		<dc:creator>Mihalytch</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cp1251]]></category>
		<category><![CDATA[UTF-8]]></category>
		<category><![CDATA[кодировка]]></category>

		<guid isPermaLink="false">http://mihalytch.org.ua/news/10.html</guid>
		<description><![CDATA[Под катом представлено несколько функций для PHP для перекодировки UTF-8 в cp1251 Для выполнения вышепоставленной задачи вы можете воспользоваться стандартной функцией PHP - iconv. Ее подробное описание можно найти на официальном сайте PHP. Либо воспользоваться одной из функций для перекодировки кириллицы из UTF-8 в windows-1251, представленных ниже. function utf8_to_cp1251($utf8) { $windows1251 = ""; $chars = [...]]]></description>
			<content:encoded><![CDATA[<p>Под катом представлено несколько функций для PHP для перекодировки UTF-8 в cp1251<br />
<span id="more-10"></span></p>
<p>Для выполнения вышепоставленной задачи вы можете воспользоваться стандартной функцией PHP - <a href="http://mihalytch.org.ua/go.php?url=ua2.php.net/manual/ru/function.iconv.php" target="_blank" title="iconv">iconv</a>. Ее подробное описание можно найти на официальном сайте PHP.</p>
<p>Либо воспользоваться одной из функций для перекодировки кириллицы из UTF-8 в windows-1251, представленных ниже.</p>
<pre class="brush: php">
function utf8_to_cp1251($utf8) {

    $windows1251 = "";
    $chars = preg_split("//",$utf8);

    for ($i=1; $i&lt;count($chars)-1; $i++) {
        $prefix = ord($chars[$i]);
        $suffix = ord($chars[$i+1]);

        if ($prefix==215) {
            $windows1251 .= chr($suffix+80);
            $i++;
        } elseif ($prefix==214) {
            $windows1251 .= chr($suffix+16);
            $i++;
        } else {
            $windows1251 .= $chars[$i];
        }
    }

    return $windows1251;
}

function Utf8Win($str,$type="w")  {
    static $conv='';

    if (!is_array($conv))  {
        $conv = array();

        for($x=128;$x&lt;=143;$x++)  {
            $conv['u'][]=chr(209).chr($x);
            $conv['w'][]=chr($x+112);

        }

        for($x=144;$x&lt;=191;$x++)  {
            $conv['u'][]=chr(208).chr($x);
            $conv['w'][]=chr($x+48);
        }

        $conv['u'][]=chr(208).chr(129);
        $conv['w'][]=chr(168);
        $conv['u'][]=chr(209).chr(145);
        $conv['w'][]=chr(184);
        $conv['u'][]=chr(208).chr(135);
        $conv['w'][]=chr(175);
        $conv['u'][]=chr(209).chr(151);
        $conv['w'][]=chr(191);
        $conv['u'][]=chr(208).chr(134);
        $conv['w'][]=chr(178);
        $conv['u'][]=chr(209).chr(150);
        $conv['w'][]=chr(179);
        $conv['u'][]=chr(210).chr(144);
        $conv['w'][]=chr(165);
        $conv['u'][]=chr(210).chr(145);
        $conv['w'][]=chr(180);
        $conv['u'][]=chr(208).chr(132);
        $conv['w'][]=chr(170);
        $conv['u'][]=chr(209).chr(148);
        $conv['w'][]=chr(186);
        $conv['u'][]=chr(226).chr(132).chr(150);
        $conv['w'][]=chr(185);
    }

    if ($type == 'w') {
        return str_replace($conv['u'],$conv['w'],$str);
    } elseif ($type == 'u') {
        return str_replace($conv['w'], $conv['u'],$str);
    } else {
        return $str;
    }
}</pre>
<img src="http://mihalytch.org.ua/?ak_action=api_record_view&id=10&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://mihalytch.org.ua/programming/php/convert-utf8-cp1251.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
