【问题标题】:How to show double quote in input tag?如何在输入标签中显示双引号?
【发布时间】:2017-10-04 03:20:47
【问题描述】:

如何在输入标签中显示双引号?

我的$testi test "hello"

然后像这样输入

<input name="test" type="text" value="<?PHP echo $test; ?>">

当输入中的测试代码仅显示i test

如何在输入标签中显示i test "hello"

【问题讨论】:

  • value 属性使用单引号。 value='&lt;?PHP echo $test; ?&gt;'

标签: html input


【解决方案1】:

尝试使用htmlspecialchars或使用htmlentities

<input name="test" type="text" value="<?php echo htmlspecialchars($test); ?>">

<input name="test" type="text" value="<?php echo htmlentities($test); ?>">

或者使用 PHP echo 你可以做到

<?php echo '<input name="test" type="text" value="'.$test.'">'; ?>

【讨论】:

  • 最后一个echo 将产生value="i test "hello"",所以这行不通。
【解决方案2】:

使用html_entity_decode,因为您使用的是php,如下所示:

&lt;input name="test" type="text" value="&lt;?PHP echo html_entity_decode($test); ?&gt;"&gt;

【讨论】:

  • 我想你的意思是htmlentities()
  • 没有。这正是我的意思。因为htmlentities是它的反面
猜你喜欢
  • 1970-01-01
  • 2014-01-04
  • 2018-12-17
  • 1970-01-01
  • 2015-01-10
  • 2013-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多