’ при перекодировке текста с CP1252 в UTF-8

263
10 марта 2018, 20:42

В начале я имею вот такой текст:

$str1 = 'he was responsible for most of Apple’s day-to-day operations';

Как сделали такой результат у меня информации нету. Но методом перебора выяснил что вот это возвращает нужный результат

$description = mb_convert_encoding($description, 'CP1252', 'UTF-8');

То есть

$str2 = "he was responsible for most of Apple's day-to-day operations";

Если это писать в базу тогда получаю:

General error: 1366 Incorrect string value: '\x92s bus

Потому что в базе кодировкаа utf8_general_ci а текст я перевел в кодировку CP1252.

А когда меняю кодировку на UTF-8 получаю $str1 с ’

В результате придумал вот такой метод как получить нормальный текст и в кодироке utf-8

$str2 = mb_convert_encoding($str2, 'UTF-8', 'UTF-8');

На выходе получил нужный текст в UTF-8 где апостроф есть апострофом, а не кракозяброю.

Мой вопрос заключаеться в следующем, что именно делает эта команда

$str2 = mb_convert_encoding($str2, 'UTF-8', 'UTF-8');

Можно предположыть что коды символов она не трогает, не перекодирует их в другую кодировку, а просто указывает что эти коды нужно понимать с помощью другой кодировки.

В моем случае вроде текст в кодировке UTF-8 приняли за CP1252 и перекодировали его с CP1252 в UTF-8. Но он изначально уже был в UTF-8.

И когда я делаю обратное, то есть с UTF-8 в CP1252. Тогда коды символов возвращаются в начальное состояние но текст помечен как CP1252. И в результате получаю ошибку при записи в базу.

Эта команда просто берет коды символом и принимает его как UTF-8 и переводит в UTF-8, и текст уже помечен как UTF-8 и никаких ошыбок нету.

Но это все предположения и хотелось бы узнать более точную информацию

UPDATE: Добавлю дамп таблици которая есть у меня в начале и с которой получаю данные. А именно с поля field_description_value

CREATE TABLE `field_data_field_description` (
  `entity_type` varchar(128) NOT NULL DEFAULT '' COMMENT 'The entity type this data is attached to',
  `bundle` varchar(128) NOT NULL DEFAULT '' COMMENT 'The field instance bundle to which this row belongs, used when deleting a field instance',
  `deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'A boolean indicating whether this data item has been deleted',
  `entity_id` int(10) UNSIGNED NOT NULL COMMENT 'The entity id this data is attached to',
  `revision_id` int(10) UNSIGNED DEFAULT NULL COMMENT 'The entity revision id this data is attached to, or NULL if the entity type is not versioned',
  `language` varchar(32) NOT NULL DEFAULT '' COMMENT 'The language for this data item.',
  `delta` int(10) UNSIGNED NOT NULL COMMENT 'The sequence number for this data item, used for multi-value fields',
  `field_description_value` longtext,
  `field_description_format` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Data storage for field 96 (field_description)';
INSERT INTO `field_data_field_description` (`entity_type`, `bundle`, `deleted`, `entity_id`, `revision_id`, `language`, `delta`, `field_description_value`, `field_description_format`) VALUES
('node', 'honor_roll', 0, 31114, 34896, 'und', 0, 'The CEO of Apple, he joined Apple in March 1998 as SVP of Worldwide Operations and also served as EVP of Worldwide Sales and Operations. He was COO until January 2011 when he began serving as acting CEO of Apple when Steve Jobs began a medical leave. He was named the CEO on August 24, 2011, succeeding Steve Jobs, who died on October 5, 2011, from pancreatic cancer. In early 2012, he was awarded compensation of 1 million shares, vesting in 2016 and 2021, by Apple\'s Board of Directors. As of January 2012, his total compensation package made him the world\'s highest paid CEO. He grew up in Robertsdale, Alabama, near Mobile. His father was a shipyard worker, while his mother was a homemaker. He graduated from high school at Robertsdale High School, earned a B.S. degree in industrial engineering from Auburn University in 1982, and his M.B.A. from Duke University\'s Fuqua School of Business in 1988. He spent seven months at Compaq as VP for Corporate Materials before he was hired by Steve Jobs to join Apple in 1998. He initially served as Senior Vice President for Worldwide Operations. Prior to that, he served as the chief operating officer (COO) of the computer reseller division of Intelligent Electronics and spent 12 years in IBM\'s personal computer business as the director of North American Fulfillment. He is credited with pulling Apple out of manufacturing by closing factories and warehouses around the world. This helped the company reduce inventory levels and streamline its supply chain, dramatically increasing margins. In January 2007, he was promoted to COO. He served as CEO for two months in 2004, when Jobs was recovering from pancreatic cancer surgery. In 2009, he again served as CEO for several months while Jobs took a leave of absence for a liver transplant. In January 2011, Apple\'s Board of Directors approved a third medical leave of absence requested by Jobs. During that time, he was responsible for most of Apple’s day-to-day operations while Jobs made most major decisions. Following the resignation of Jobs, he was made CEO of Apple Inc. on August 24, 2011. He also serves on the board of directors of Nike. In April 2012, Time Magazine included him on its annual 100 Most Influential People in the World list. While giving the 2010 commencement speech at Auburn University, he emphasized the importance of intuition in guiding his life\'s biggest choices, and followed by stating that preparation and hard work are also necessary to execute on that intuition. He regularly begins sending emails at 4:30 am and used to hold Sunday night staff meetings by telephone to prepare for the next week. He is a fitness enthusiast and enjoys hiking, cycling, and going to the gym.', NULL);
READ ALSO
как исправит ошибку PHP CORE WARNING – YII\BASE\ERROREXCEPTION

как исправит ошибку PHP CORE WARNING – YII\BASE\ERROREXCEPTION

когда слил сайт на хостинг выводит ошибку PHP CORE WARNING – YII\BASE\ERROREXCEPTION половина страниц выводится без ошибкина локальноь сервере ошибок нет

275
Почему не работает file_get_html?

Почему не работает file_get_html?

Использую библиотеку Simple Dom Html

381
Многомерный массив на php

Многомерный массив на php

Помогите пожалуйста с многомерным массивом php

231
В чём ошибка в коде?

В чём ошибка в коде?

Помогите пожалуйста, делаю бота для игры в крестики-ноликиВ теории если сообщение "а1", то переменная $a1 должна стать ровна "x" и в переменной...

263