dongyan1841 2017-06-21 00:37
浏览 44

添加php变量作为链接地址的一部分?

I'm trying to add a variable as a part of a link, but I haven't could do it.

<?php
$fname=$data_array["firstname"];
echo '<a class="pin-button" href="https://myweb.com/description=$fname&amp;editable=false&amp;success_url=http%3A%2F%myweb.com%2Fsuccess"><img src="http://myweb.com/images/button.png" width="120"></a>';
?>

the link works perfect, but I need to add the variable after description=$fname

Thanks a lot!

  • 写回答

1条回答 默认 最新

  • dtd5644 2017-06-21 00:43
    关注

    1: $variables don't work inside single quotes, instead of

    echo '<a href="$path">'`
    

    try

    echo "<a href='$path'>"
    

    2: If you wish to use single quotes you can use concatenation instead:

    echo '<a href="'.$path.'">'
    

    3: In either case, you should be escaping your strings when printing them inside HTML:

    echo "<a href='".htmlspecialchars($path, ENT_QUOTES)."'>"
    

    This prevents characters (such as quotes and less-than signs) having unintended effects, and prevents exploits by maliciously crafted data.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行