【问题标题】:How to replace section of url based on form input如何根据表单输入替换 url 部分
【发布时间】:2012-01-29 11:20:28
【问题描述】:

我在这里找到了一些示例,这就是我编写代码的基础。但是少了一件。我需要在 URL 字符串的末尾添加“&next=http://facebook.com”,以便最终结果以:

https://www.facebook.com/dialog/pagetab?app_id=########&next=http://facebook.com

(######## = 输入数据)

到目前为止,这就是我所拥有的:

https://www.facebook.com/dialog/pagetab?app_id=" . $_POST['文件夹'] ); }

?>

< input type="text" name="folder" id="folder" />
< input type="submit" name="bt" id="bt" value="Go To" />

【问题讨论】:

  • 我不是PHP程序员,但我相信它有字符串连接功能。
  • @Verbeia 他在代码中使用了连接运算符。这个问题我不清楚。

标签: php forms url post replace


【解决方案1】:
<?php
if (isset($_POST['bt'])) {
    $newLocation = "https://www.facebook.com/dialog/pagetab?app_id=".$_POST['folder'];
    $newLocation .= "&next=http://facebook.com";
    header("Location: " . $newLocation);
}
?>

您也可以将它们全部连接在一行中(如下所示)。就我个人而言,我喜欢像上面那样分解它,但是 - 这完全取决于程序员。

$newLocation = "https://www.facebook.com/dialog/pagetab?app_id=".$_POST['folder'] . "&next=http://facebook.com";

【讨论】:

  • Np。如果您觉得答案有帮助,请记得接受它作为答案。
【解决方案2】:

试试

<?php
if (isset($_POST['bt'])) {
    $newLocation = 'https://www.facebook.com/dialog/pagetab?' . 
    http_build_query(array('app_id' => $_POST['folder'], 'next' => 'http://facebook.com'));
    header("Location: " . $newLocation);
}

【讨论】:

    猜你喜欢
    • 2022-12-08
    • 1970-01-01
    • 2011-05-29
    • 2022-11-23
    • 2018-12-21
    • 2013-10-04
    • 2022-11-11
    • 2013-07-05
    • 2017-01-15
    相关资源
    最近更新 更多