dqwnxdhb88531 2017-03-22 20:05
浏览 32
已采纳

PHP:字符串数据属性被拆分

So I'm creating buttons from a result set of MySQL query, and binding data- attributes from those results. All fine with numbers and dates, but when the field is a string, the data- attribute created gets split by the whitespaces.

My PHP code:

$options = "";
while($row=mysqli_fetch_array($of)) {
   $options .= "<p><a class='btn btn-default btn-open-modal' role='button' data-id=".htmlentities($row["art_id"])." data-name=".htmlentities($row["art_name"]).">See details &raquo;</a></p>";
}

When I inspect the button, I get something like data-name="nike" shox="" (if the name in the table is "nike shox"), but data-id="1" is just fine.

How can I get prevent that the data-name gets split?

  • 写回答

1条回答 默认 最新

  • dongshuo6503 2017-03-22 20:10
    关注

    Change this...

    $options .= "<p><a class='btn btn-default btn-open-modal' role='button' data-id=".htmlentities($row["art_id"])." data-name=".htmlentities($row["art_name"]).">See details &raquo;</a></p>";
    

    To this...

    $options .= '<p><a class="btn btn-default btn-open-modal" role="button" data-id="' . htmlentities($row["art_id"]) . '" data-name="' . htmlentities($row["art_name"]) . '">See details &raquo;</a></p>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理