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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名