4X_Pro
Руководитель Проекта
Настоящий Компьютерщик
 Откуда: Москва Всего сообщений: 3031 Рейтинг пользователя: 75 Дата регистрации на форуме: 29 сен. 2001
|
Профиль | ИгнорироватьNEW! Сообщение отправлено: 9 февраля 2006 20:14
Недавно при написании RSS-модуля столкнулся с проблемой: как перекодировать текст из cp1251 в UTF-8. Сначала пытался функцией utf8_encode, но не получилось: она считает, что исходная строка - в latin1 и перекодирует ее соответственно. В результате пришлось производить перекодировку методом глобальной замены всех символов с помощью вот такого кода: $text = str_replace(chr(208),chr(208).chr(160),$text); # Р $text = str_replace(chr(192),chr(208).chr(144),$text); # А $text = str_replace(chr(193),chr(208).chr(145),$text); # Б $text = str_replace(chr(194),chr(208).chr(146),$text); # В $text = str_replace(chr(195),chr(208).chr(147),$text); # Г $text = str_replace(chr(196),chr(208).chr(148),$text); # Д $text = str_replace(chr(197),chr(208).chr(149),$text); # Е $text = str_replace(chr(168),chr(208).chr(129),$text); # Ё $text = str_replace(chr(198),chr(208).chr(150),$text); # Ж $text = str_replace(chr(199),chr(208).chr(151),$text); # З $text = str_replace(chr(200),chr(208).chr(152),$text); # И $text = str_replace(chr(201),chr(208).chr(153),$text); # Й $text = str_replace(chr(202),chr(208).chr(154),$text); # К $text = str_replace(chr(203),chr(208).chr(155),$text); # Л $text = str_replace(chr(204),chr(208).chr(156),$text); # М $text = str_replace(chr(205),chr(208).chr(157),$text); # Н $text = str_replace(chr(206),chr(208).chr(158),$text); # О $text = str_replace(chr(207),chr(208).chr(159),$text); # П $text = str_replace(chr(209),chr(208).chr(161),$text); # С $text = str_replace(chr(210),chr(208).chr(162),$text); # Т $text = str_replace(chr(211),chr(208).chr(163),$text); # У $text = str_replace(chr(212),chr(208).chr(164),$text); # Ф $text = str_replace(chr(213),chr(208).chr(165),$text); # Х $text = str_replace(chr(214),chr(208).chr(166),$text); # Ц $text = str_replace(chr(215),chr(208).chr(167),$text); # Ч $text = str_replace(chr(216),chr(208).chr(168),$text); # Ш $text = str_replace(chr(217),chr(208).chr(169),$text); # Щ $text = str_replace(chr(218),chr(208).chr(170),$text); # Ъ $text = str_replace(chr(219),chr(208).chr(171),$text); # Ы $text = str_replace(chr(220),chr(208).chr(172),$text); # Ь $text = str_replace(chr(221),chr(208).chr(173),$text); # Э $text = str_replace(chr(222),chr(208).chr(174),$text); # Ю $text = str_replace(chr(223),chr(208).chr(175),$text); # Я $text = str_replace(chr(224),chr(208).chr(176),$text); # а $text = str_replace(chr(225),chr(208).chr(177),$text); # б $text = str_replace(chr(226),chr(208).chr(178),$text); # в $text = str_replace(chr(227),chr(208).chr(179),$text); # г $text = str_replace(chr(228),chr(208).chr(180),$text); # д $text = str_replace(chr(229),chr(208).chr(181),$text); # е $text = str_replace(chr(184),chr(209).chr(145),$text); # ё $text = str_replace(chr(230),chr(208).chr(182),$text); # ж $text = str_replace(chr(231),chr(208).chr(183),$text); # з $text = str_replace(chr(232),chr(208).chr(184),$text); # и $text = str_replace(chr(233),chr(208).chr(185),$text); # й $text = str_replace(chr(234),chr(208).chr(186),$text); # к $text = str_replace(chr(235),chr(208).chr(187),$text); # л $text = str_replace(chr(236),chr(208).chr(188),$text); # м $text = str_replace(chr(237),chr(208).chr(189),$text); # н $text = str_replace(chr(238),chr(208).chr(190),$text); # о $text = str_replace(chr(239),chr(208).chr(191),$text); # п $text = str_replace(chr(240),chr(209).chr(128),$text); # р $text = str_replace(chr(241),chr(209).chr(129),$text); # с $text = str_replace(chr(242),chr(209).chr(130),$text); # т $text = str_replace(chr(243),chr(209).chr(131),$text); # у $text = str_replace(chr(244),chr(209).chr(132),$text); # ф $text = str_replace(chr(245),chr(209).chr(133),$text); # х $text = str_replace(chr(246),chr(209).chr(134),$text); # ц $text = str_replace(chr(247),chr(209).chr(135),$text); # ч $text = str_replace(chr(248),chr(209).chr(136),$text); # ш $text = str_replace(chr(249),chr(209).chr(137),$text); # щ $text = str_replace(chr(250),chr(209).chr(138),$text); # ъ $text = str_replace(chr(251),chr(209).chr(139),$text); # ы $text = str_replace(chr(252),chr(209).chr(140),$text); # ь $text = str_replace(chr(253),chr(209).chr(141),$text); # э $text = str_replace(chr(254),chr(209).chr(142),$text); # ю $text = str_replace(chr(255),chr(209).chr(143),$text); # я
Правильнее было бы, конечно, сформировать массив и вызывать функцию замены для него, но на это просто не было времени...
--- Каждый человек всегда может найти, чем он может быть полезен окружающим. Проблема только в одном: слишком многие не хотят это искать.
|