如何转义html输入的引号(使用php)?

编程入门 行业动态 更新时间:2024-10-21 11:36:07
本文介绍了如何转义html输入的引号(使用php)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复:

如果我使用预设的HTML输入,例如:

If I use a preset HTML input, eg:

$lmao=$_POST['lmao']; echo <<<EOD <input value="{$lmao}" name="lmao" type="text"> EOD;

如果 字符进入变量,则会导致便便

if a " character gets into the variable, it will result in poo, and also a data loss on re-submission.

我当然可以:

preg_replace('/"/', '',$lmao);

但是如果我想保留该报价怎么办?

But what if I wanted to keep that quote?

推荐答案

在HTML属性中输出的所有用户输入数据都应通过htmlspecialchars运行。这将对引号和其他字符进行编码:

All user-inputted data that is being output within HTML attributes should be run through htmlspecialchars. This encodes quotes and other characters:

echo '<input value="'.htmlspecialchars($lmao).'" name="lmao" type="text">';

更多推荐

如何转义html输入的引号(使用php)?

本文发布于:2023-10-25 08:24:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1526447.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:引号   html   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!