doutu6616 2011-07-19 19:54
浏览 37

PHP的帖子没有被转义。 字符编码?

I have a string that has an apostrophe character that can't be escaped or searched for.

Essentially I have a string that is being pulled from a 3rd party service. It is encoded as ISO-8859-1 and when it comes in, I can't escape a particular character. A sample string is below

We’re proud to offer some exciting products that come with a full manufacturer's warranty

In this case, using mysql_real_escape_string won't escape the first apostrophe, but it will escape the others. No matter what I do, I can't seem to escape the string or replace it with a normal apostrophe.

Here is what I use to acquire the file.

$opts = array(
          'http'=>array(
            'method'=>"GET",
            'header'=>"Content-Type: text/html; charset=ISO-8859-1" 
            )
        );
        $context = stream_context_create($opts); 
        $html = file_get_contents($url, false, $context);

If I try an convert the string to UTF-8 using mb_convert_encoding(), it doesn't alter it in any way. I tried to simply replace the string using str_ireplace() on the ISO-8859-1 string and mb_ereg_replace on the UTF-8 string. Nothing has any effect.

  • 写回答

2条回答 默认 最新

  • douluo7366 2011-07-19 19:58
    关注

    The first apostrophe is actually the character RIGHT SINGLE QUOTATION MARK (U+2019, ) and not U+0027 ('). And that is not escaped by mysql_real_escape_string.

    But besides that, U+2019 is not contained in the ISO 8859-1 character set and hence cannot be encoded with ISO 8859-1.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)