dongyirong3564 2017-03-10 23:59
浏览 60

需要PHP echo才能在缓冲区上生成文本超链接

I have a php form on my site. The form ultimately produces an article submitted by the user.

One of the data fields in the form, is a drop down menu so the user can select which publication they represent.

Currently, the form works if I am only trying to display the name of their publication.

However... I would also like that name to be a clickable link to their respective publication.

In an attempt to achieve this, I set my form up like this:

    Form: <select name="publication" id="publication">
          <option value="http://www.espn.com">ESPN</option>
          <option value="http://www.cnn.com">CNN</option>
          <option value="http://www.abcnews.com">ABC</option>
          <option value="http://www.cbsnews.com">CBS</option>
          <option value="http://www.foxnews.com">FOX</option>
          </select>

And the echo is set up like this:

    Echo:

   <?php $publication  = htmlspecialchars($_POST['publication']); echo $publication; ?>

Unfortunately, the result produces the full URL instead of the Text Link I am trying to achieve.

Not sure how I am supposed to code the form or the echo to achieve the desired clickable text link.

  • 写回答

2条回答 默认 最新

  • duanhuokuang5280 2017-03-11 00:05
    关注

    The value of $_POST['publication'] is going to be the chosen <option>'s value, not the display name.

    If you want to display the link along with the name, consider encoding the list of publications into a static array, then outputting that:

    $publications = [
        "media1" => "link",
        "media2" => "link"
    ]
    
    if (array_key_exists($_POST["publication"], $publications)) {
        echo '<a href="' . $publications[$_POST["publication"]] . '">' . htmlspecialchars($_POST["publication"]) . '</a>';
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来