Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
URL中没有参数的PHP页面的默认值_Php_Arguments_Default - Fatal编程技术网

URL中没有参数的PHP页面的默认值

URL中没有参数的PHP页面的默认值,php,arguments,default,Php,Arguments,Default,我是PHP游戏的新手,我的问题是理解问题,所以我为101个问题道歉 我在网站的子文件夹中有一个index.php。 我知道我可以通过URL将参数传递给页面 https://example.com/subfolder?id=1234 如果有人导航到 https://example.com/subfolder 如果没有参数,如何提供默认的4321 我从其他堆栈溢出问题中收集到的代码是 <?php $id = (isset($_GET["id"])) ? $_GET["id"] : "4

我是PHP游戏的新手,我的问题是理解问题,所以我为101个问题道歉

我在网站的子文件夹中有一个index.php。 我知道我可以通过URL将参数传递给页面

https://example.com/subfolder?id=1234
如果有人导航到

https://example.com/subfolder
如果没有参数,如何提供默认的4321

我从其他堆栈溢出问题中收集到的代码是

<?php
  $id = (isset($_GET["id"])) ? $_GET["id"] : "4321";
  echo "<some html>" . $id . "<some more html>";
?>

我也试过了

<?php
  if (isset($_GET['id'])) {
    $id = $_GET['id'];
  } else {
    $id = "4321";
  }
  echo "<some html>" . $id . "<some more html>";
?>

我相信这只是写同样东西的另一种方式

代码在提供参数时从URL中提取参数,页面工作正常,但在未提供参数时不提供默认值。我怀疑这与没有定义id变量有关,如果它不在URL中,但我不知道

如果你能帮忙,非常感谢

编辑:以防万一,詹姆斯,我包括了我正在使用的实际回音线(sans域)。其他一切都和我上面键入的一样

echo '<iframe width="70%" padding-bottom="20px" height="900" scrolling="yes" frameborder="no"
        src="https://example.com/eventlist/415c564448271d0f1504/?point_of_sale_id=' . $id . '"></iframe>';
echo';
编辑:当我查看页面源代码时,这是PHP返回的内容

<iframe width="70%" padding-bottom="20px" height="900" scrolling="yes" frameborder="no"
        src="https://example.com/eventlist/415c564448271d0f1504/?point_of_sale_id="></iframe>

这是我开始工作的代码,我必须添加一个额外的步骤

<?php
  $id = $_GET["id"];
  $linkId = (isset($id)) ? $id : "4321";
  echo "<some html>" . $linkId . "<some more html>";
?>


我很想知道是否有人能解释为什么原始代码不起作用。

您的两个代码示例都应该可以正常工作,所以有人告诉我,我们还缺少这个谜题的另一部分。如果这些引号
来自您的真实代码,请将它们更改为:
然后重试。在PHP中只有
是有效的引号。您可能还想查看:。谢谢Magnus。我已经修改了代码。我的代码没有倾斜的。我真的不知道它们是如何潜入其中的。