duanbu9345 2012-03-13 19:42
浏览 78
已采纳

在php中访问textarea内容时的特殊字符

I am getting special characters from the textarea input on my form

So if I enter the below text

Philbrick, whose “In the Heart of the Sea: The Tragedy of the Whaleship Essex” recounted the real-life inspiration for Melville’s shipwreck, wears his erudition lightly.

I get the following when I access it in php.

Philbrick, whose “In the Heart of the Sea: The Tragedy of the Whaleship Essex†recounted the real-life inspiration for Melville’s shipwreck, wears his erudition lightly.

I tried the below before accessing the text , but replace is not working. Are these special characters not matching when I am copy pasting those in the code or its something else which is missing?

$string = htmlspecialchars($_POST["t"]) ;
$string = html_entity_decode($string, ENT_QUOTES, "UTF-8");
$string = str_replace('“', "\"", $string);
$string = str_replace('’', "'", $string);
  • 写回答

2条回答 默认 最新

  • dtsi9484 2012-03-13 20:09
    关注

    There may not be anything wrong with what you're seeing. You may not need to mangle the $_POST with htmlentities corrections or otherwise. It could be that you're looking at a barebones browser output.

    In case you're debugging this by spitting it out with something like print_r( $_POST ); die;, make sure that somewhere above it in your page you have a meta line setting your character encoding to UTF-8:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    That will ensure that the smart characters (presumably pasted from somewhere) render properly on screen.

    Completely unrelated: Excellent book, BTW. Love the beginning scene with gaunt sailors hoarding their piles of bones.

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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化