【问题标题】:How to append dynamic text to url in PHP?如何在 PHP 中将动态文本附加到 url?
【发布时间】:2014-06-20 03:00:24
【问题描述】:

我有一个方法类型为 post 的 html 表单,现在我想在 PHP 中将文本附加到我的网站 url。文本动态变化。

当前网址:

www.example.com/index.php

预期网址:

www.example.com/index.php/hotels-in-bangalore 

(或)

www.example.com/index.php?qry=hotels-in-bangalore

我只想附加文本,除了每件事都应该保持不变。谢谢。

【问题讨论】:

  • 您能否发布您的 HTML 表单代码,以便我们了解您想要做什么?

标签: javascript php jquery url url-rewriting


【解决方案1】:

我不确定您为什么要尝试完成,但这里有几个解决方案:

将 url 放入表单操作中:

<form action="index.php?qry=hotels-in-bangalore" method="post">

或者你可以在 php 中完成

if (!empty($_POST['name']) {//put some logic here
  header("Location: index.php?qry=hotels-in-bangalore");
  exit;
}

【讨论】:

    【解决方案2】:

    如果要立即提交后重定向到正确的页面,则需要使用JavaScript。

    所以它会是这样的:

    <form>
      <input type="text" name="tbSearch" id="tbSearch" />
      <input type="submit" id="submitSearch" value="Submit" />
    </form>
    
    <script type="text/javascript">
    $("#submitSearch").click(function() {
       window.location.href="index.php?qry=" + encodeURIComponent($("#tbSearch").val());
    });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      • 2017-12-16
      • 2018-11-02
      相关资源
      最近更新 更多