doujiang7258 2018-03-29 05:22
浏览 11
已采纳

使用php发布输入的人口值,因为“

I'm trying to populate a html field using php but if there is a " on the variable it just closes the value paramenter. How can I prevent this from happening?

<input type="text" name="txtnome" class="form-control" value="<?php echo "$nome" ?>" required>
  • 写回答

1条回答 默认 最新

  • duanjing7651 2018-03-29 05:25
    关注

    You can do this:

    <input type="text" name="txtnome" class="form-control" value="<?php echo htmlspecialchars($nome) ?>" required>
    

    http://php.net/manual/en/function.htmlspecialchars.php

    Since

    echo "$nome";
    echo '$nome';
    echo $nome;
    

    are identical to each other, it'll only work with htmlspecialchars.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题