奇怪的编码问题

2016-07-07 15:06 来源:www.chinab4c.com 作者:ecshop专家



我在做EC的二次开发,增加了一个函数,当我在测试是否能正确接收变量的时候,我用{$goods}输出了数组,都能正常显示,我以为没问题了,可是当我用{$goods.name}输出商品名称的时候,却出现了乱码,这是怎么回事?

  1. function get_index_goods($cats = '',$num ='')
  2. {
  3. $time = gmtime();
  4. $order_type = 0;
  5. $sql = 'SELECT g.goods_id, g.is_index, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
  6. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  7. "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " .
  8. "g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " .
  9. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
  10. 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
  11. "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  12. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  13. 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' .
  14. " AND g.is_index = 1 ";
  15. $sql .= $order_type == 0 ? ' ORDER BY g.goods_id desc' : ' ORDER BY rnd';
  16. if($num != ''){
  17. $sql .= " LIMIT $num ";
  18. }
  19. $result = $GLOBALS['db']->getAll($sql);

  20. $goods = array();
  21. foreach ($result AS $idx => $row)
  22. {
  23. if ($row['promote_price'] > 0)
  24. {
  25. $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
  26. $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
  27. }
  28. else
  29. {
  30. $goods[$idx]['promote_price'] = '';
  31. }

  32. $goods[$idx]['id']= $row['goods_id'];
  33. $goods[$idx]['name']= $row['goods_name'];
  34. $goods[$idx]['brief']= $row['goods_brief'];
  35. $goods[$idx]['brand_name']= $row['brand_name'];
  36. $goods[$idx]['goods_style_name']= add_style($row['goods_name'],$row['goods_name_style']);
  37. $goods[$idx]['short_name']= $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
  38. $goods[$idx]['short_style_name']= add_style($goods[$idx]['short_name'],$row['goods_name_style']);
  39. $goods[$idx]['market_price'] = price_format($row['market_price']);
  40. $goods[$idx]['shop_price']= price_format($row['shop_price']);
  41. $goods[$idx]['thumb']= get_image_path($row['goods_id'], $row['goods_thumb'], true);
  42. $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
  43. $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
  44. }
  45. return $goods;
  46. }
复制代码
这样输出则会出现乱码:


  1. <!-- {foreach from=$index_goods item=indexgoods} -->
  2. <!-- {foreach from=$indexgoods item=igoods key=key} -->
  3. {$igoods.name}&nbsp;
  4. <!-- {/foreach} -->
  5. <!-- {/foreach} -->
复制代码

回答:
没人?自己顶