dsmupo6631 2013-03-06 19:17
浏览 24
已采纳

通过POST将PHP字符串发送到PHP。 在回收它时得到奇怪的字符

So I am making a simple script where I send a HTML string via POST to PHP and when I try to echo it out it gets encoded with some weird characters

The string Im sending:

'Yo <i>whats up</i>'

What I get when I echo it out with PHP

Yo+%3Ci%3Ewhats+up%3C%2Fi%3E 

What is going on here? Is there some PHP method I can use to revert it back to the original HTML string?

  • 写回答

2条回答 默认 最新

  • dow72046 2013-03-06 19:20
    关注

    You want to use

    echo htmlspecialchars(urldecode('Yo+%3Ci%3Ewhats+up%3C%2Fi%3E'));
    

    The reason is that your data gets x-www-form-urlencoded for posting. So on the server-side, you have to decode it again - that's what urldecode() does.

    htmlspecialchars() prevents your HTML-Tags to be rendered as such so they are just displayed as a string (if that's what you want).

    So, in an HTML context, echo urldecode('Yo+%3Ci%3Ewhats+up%3C%2Fi%3E'); would output

    Yo whats up

    And if you also wrap it with htmlspecialchars(), your output would be

    Yo <i>whats up</i>

    again.

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

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置