Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Проблема с кодировкой


Gann

Recommended Posts

Добрый вечер!

 

Столкнулся с проблемой в кодировке.

 

Код:

<?php
class ControllerFeedLatestProductsRSS extends Controller {
	public function index() {
		if ($this->config->get('latest_products_rss_status')) {
			$output = '<?xml version="1.0" encoding="UTF-8" ?>';
			$output .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
			$output .= '<channel>';
			$output .= '<atom:link href="' . HTTP_SERVER . 'index.php?route=feed/latest_products_rss" rel="self" type="application/rss+xml" />';
			$output .= '<title><![CDATA[' . $this->config->get('config_name') . ']]></title>';
			$output .= '<description><![CDATA[' . $this->config->get('config_meta_description') . ']]></description>';
			$output .= '<link><![CDATA[' . HTTP_SERVER . ']]></link>';
			$this->load->model('catalog/product');
			$this->load->model('localisation/currency');
			$this->load->model('tool/image');
			$this->load->language('feed/latest_products_rss');

			$limit = $this->config->get('latest_products_rss_limit') ? $this->config->get('latest_products_rss_limit') : 100;
			$show_price = $this->config->get('latest_products_rss_show_price');
			$include_tax = $this->config->get('latest_products_rss_include_tax');
			$show_image = $this->config->get('latest_products_rss_show_image');
			if ($show_image) {
				$image_width = $this->config->get('latest_products_rss_image_width') ? $this->config->get('latest_products_rss_image_width') : 100;
				$image_height = $this->config->get('latest_products_rss_image_height') ? $this->config->get('latest_products_rss_image_height') : 100;
			}
			$products = $this->model_catalog_product->getLatestProducts($limit);
			if (isset($this->request->get['currency'])) {
				$currency = $this->request->get['currency'];
			} else {
				$currency = $this->currency->getCode();
			}
			foreach ($products as $product) {

				if ($product['description']) {

					$title = html_entity_decode($product['name']);
					$link = $this->url->link('product/product', 'product_id=' . $product['product_id']);
					$description = "";
					if ($show_price) {
						if ($include_tax) {
							if ((float) $product['special']) {
								$price = $this->currency->format($this->tax->calculate($product['special'], $product['tax_class_id']), $currency, FALSE, TRUE);
							} else {
								$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id']), $currency, FALSE, TRUE);
							}
						} else {
							if ((float) $product['special']) {
								$price = $this->currency->format($product['special'], $currency, FALSE, TRUE);
							} else {
								$price = $this->currency->format($product['price'], $currency, FALSE, TRUE);
							}
						}
						$description .= '<p><strong>' . $this->language->get('text_price') . ' ' . $price . '</strong></p>';
					}

					if ($show_image && $product['image'] != '') {
						$image_url = $this->model_tool_image->resize($product['image'], $image_width, $image_height);
						$description .= '<p><a href="' . $link . '"><img src="' . $image_url . '"></a></p>';
					}

					$description .= html_entity_decode($product['description']);

					$output .= '<item>';
					$output .= '<title><![CDATA[' . $title . ']]></title>';
					$output .= '<link>' . $link . '</link>';
					$output .= '<description><![CDATA[' . $description . ']]></description>';
					$output .= '<guid>' . $link . '</guid>';
					$output .= '<pubDate>' . date(DATE_RSS, strtotime($product['date_added'])) . '</pubDate>';

					$output .= '</item>';
				}

			}
			$output .= '</channel>';
			$output .= '</rss>';
			$this->response->addHeader('Content-Type: application/rss+xml');
			$this->response->setOutput($output);
		}
	}
}

Этот код выводит кракозяблы.

НО!

 

Добавив:

$names = $product['name'];
print_r(iconv('utf-8','utf-8',$names));

внутри foreach ($products as $product) { - я вижу нормальную кодировку.

Объясните, пожалуйста, почему так происходит и как это побороть? Спасибо

Надіслати
Поділитися на інших сайтах

Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку

×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.