htmlentities将商标转换为& acirc; cent; [英] htmlentities converts trademark into â�¢

查看:78
本文介绍了htmlentities将商标转换为& acirc; cent;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
PHP htmlentities()不能按预期工作

Possible Duplicate:
PHP htmlentities() not working as expected

我正在使用htmlentities将商标符号转换为htmlentity,但这给了我â�¢.我做错什么了吗

I am using htmlentities to convert a trademark symbol into the htmlentity, but it is giving me �. Am I doing something wrong

这是我的代码

<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://www.base.google.com/cns/1.0">
<channel>
<title>Spray Foam Systems</title>
<link>http://www.sprayfoamsys.com/store/</link>
<description>Spray Foam Rigs, Spray Foam Equipment, Sprayfoam Parts and Supplies.</description>
<?php
$con = mysql_connect(REMOVED) or die(mysql_error());
    if (!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
    mysql_select_db("sprayfoa_store", $con);
    mysql_query("SET NAMES 'utf8'", $con);

    $query = mysql_query("SELECT * FROM `catalog_product_flat_1` WHERE `visibility` = 4 ORDER BY entity_id asc")
    or die(mysql_error());
?>
<?php
    while($row = mysql_fetch_array($query))
        {
?>
<item>
<g:id><?php echo $row['entity_id']; ?></g:id>
<title><?php echo htmlentities($row['name']); ?></title>
<description><?php echo htmlentities(str_replace(array("\r\n", "\n"), ' ', $row['short_description'])); ?></description>
<g:google_product_category>Business &amp; Industrial &gt; Construction</g:google_product_category>
<g:product_type>Spray Foam Parts &amp; Supplies &gt; Fusion AP Parts</g:product_type>
<link>http://sprayfoamsys.com/store/<?php echo $row['url_path']; ?></link>
<g:image_link>http://sprayfoamsys.com/store/media/catalog/product<?php echo $row['small_image']; ?></g:image_link>
<g:condition>new</g:condition>
<g:availability>in stock</g:availability>
<g:price><?php echo $row['price']; ?></g:price>
<g:brand><?php $entity_id = $row['entity_id']; $query2 = mysql_query("SELECT * FROM `catalog_product_entity_varchar` WHERE entity_id = '$entity_id' AND attribute_id = '127'") or die(mysql_error()); while($row2 = mysql_fetch_array($query2)) { echo $row2['value']; } ?></g:brand>
<g:mpn><?php echo $row['sku']; ?></g:mpn>
</item>
<?php
}
mysql_close($con);
?>
</channel>
</rss>

推荐答案

根据手册,当不使用ISO-8859-1字符串提供此功能时,您需要提供一个字符集:

According to the manual, when not feeding this function with ISO-8859-1 strings, you need to provide a charset:

echo htmlentities($row['name'], ENT_QUOTES, 'UTF-8');

2015年3月更新:请注意,自此答案以来,此函数使用的默认字符集已针对不同版本进行了更改:

Update March 2015: Note that since this answer, the default character set this function uses has been changed for different versions:

  • PHP< 5.4:ISO-8859-1
  • PHP 5.4& 5.5:UTF-8
  • PHP> = 5.6:default_charset设置(非常受欢迎,并且应该放在第一位).
  • PHP < 5.4: ISO-8859-1
  • PHP 5.4 & 5.5: UTF-8
  • PHP >= 5.6: the default_charset setting (which is very welcome, and how it should have been in the first place).

这篇关于htmlentities将商标转换为&amp; acirc; cent;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆