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

在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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程