duanci6484 2015-06-22 15:04
浏览 106
已采纳

更新mysql表编码特殊字符

I have a mysql table called "Movies". I just found that some movies contains special characters. For example, there are some movies that I crawled and inserted in my table such as 'WALL·E' or 'Mr. and Mrs. Smith', but they are inserted in DB as 'WALL & middot ; E' and 'Mr. & amp ; Mrs. Smith'. This caused a problem in my survey application, because for example I have an autocompletion field in my survey where user should insert his/her favorite movie name, so if user try to find WALL·E, he has to insert 'WALL & middot ; E'!!

Is there any way (preferably in mysql) that I can update my table and replace all movies that contains special characters with their encoded names?

Thanks,

  • 写回答

3条回答 默认 最新

  • donglang1894 2015-06-22 15:13
    关注

    It's not a MySQL issue.

    The issue is the values you are storing to the database.

    If you want to "decode" the HTML entities in a string into the characters they represent, you can use PHP html_entity_decode function on the value you've scraped from web pages, and then store that value in the database.

    Reference: http://php.net/manual/en/function.html-entity-decode.php


    If you want to store the values in the database as encoded HTML entities, then you could search for those by taking whatever value the user is searching for, and encoding that. (That probably wasn't clear).

    If the user is searching for "Mr. & Mrs. Smith", you could encode that using the PHP htmlentities function, to return:

     Mr. & Mrs. Smith
    

    And use that as the search string.

    The downside of this approach is that there are multiple ways to encode the same character. And the way that htmlentities encodes a string may not match what was done on the webpage. It's possible that some characters may not be encoded at all, etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算