douleijiang8111 2013-08-24 03:38
浏览 145
已采纳

从MySQL数据库检索的字符串中出现特殊字符和额外空格

I have an Android app where a user can ask a question. This question is sent to a server which in turn sends it to my e-mail. I respond to the question and the response gets sent back to the server. The response is stored in a MySQL database. The user will poll the server and have the response pulled down onto their phone when it becomes available. When the response is displayed on the phone, the formatting is not right. There are special characters and extra whitespace displaying.

Here is an example of a response when it is sent to the server and placed in the database:

We live in a profit-driven society and the greater good of the people as a whole tends to get thrown to the wayside in favor of increasing one's wealth. Capitalism will not function the way it's intended to when morals are left behind.

When politicians step up to the plate they often aren't batting for the common people, but the highest bidder. It's the lobbyist representing a major corporation or some special interest group who will persuade a politician, through a financial contribution, to put their interests ahead of the interests of the general public. It's favoritism and crony capitalism at its best.

Do I feel the day will come where we'll rise beyond this? I would love to believe so, but at times it feels our current way of life has a stranglehold on us. Whether it be fear or the general lack of critical thinking that keeps people from pursuing the world/society we should have, something must change. We either will hit a breaking point and make our move or this system will continue to operate the way it does. I'll leave you with a famous quote from Edmund Burke, "The only thing necessary for the triumph of evil is that good men do nothing."

Here is what it looks like after it has been pulled down onto a phone(I shortened the misformatted response but the rest of it looks just like this part of it):

We live in a profit-driven society
and the greater good of the people
as a w=
hole tends to get thrown to the
wayside in favor of increasing one's
wealth.=
Capitalism will not function the
way its intended to when morals
are left b=
ehind.

When politicians step up to the plate
they often aren't batting for the
comm=
on people, but the highest bidder.

I do this before the response goes into the database:

$message = $dbhandler->real_escape_string($_POST["message"]);

When I create the table with the column that holds the response I assign the column the TEXT field.

I don't understand what's happening to the response either when its placed into the database or pulled from it. It has those equals signs and extra whitespace in it. Can somebody shed some light on this and offer up a remedy?

EDIT

I retrieve the response from the database like this:

$response = $dbhandler->query("SELECT response FROM qar WHERE id='$rowId'");

$row = $response->fetch_row();
if($row[0] != NULL) {
    echo($row[0]);
}
  • 写回答

1条回答 默认 最新

  • dsrruefh12970 2013-08-24 07:03
    关注

    The answer you're looking for is in your question itself:

    This question is sent to a server which in turn sends it to my e-mail.

    Sign onto your favourite terminal and run the following command for each block of and observe the output:

    $ echo -en "We live in a profit-driven society and the greater good of the people as a w" | wc -c
    76
    $ echo -en "hole tends to get thrown to the wayside in favor of increasing one's wealth." | wc -c
    76
    $ echo -en "
    Capitalism will not function the way its intended to when morals are left b" | wc -c
    76
    

    See the pattern?

    This occurs because your email uses a quoted-printable encoding which splits each line at 76 characters and uses an '=' character to indicate a line continuation. (Among other things.)

    You have multiple alternatives:

    • Encode/decode the quoted-printable body yourself.
    • Use alternative email encoding instead of quoted-printable (base64 works well)
    • Manually split the lines of your quoted-printable email body before they go beyond 76 character line limit.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能