将 URL 参数放入变量中
Put URL parameters in variables
我有 url,身份证号码是这样的:http://google.org/something.php?id=12345
和php
文件:
<?php
$noid= "0000000000000";
$id=$_GET["id"];
if(!$id)
{
$id=$noid;
}
?>
<?php echo $id ?>
<?php
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=<?php echo $id ?>';
var_dump($uri);
?>
我只需要将 12345(动态数字)放在 $uri
中,但我不知道正确的语法做吧。
刚刚试过类似的东西:
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=$id';
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=.$id.';
但不起作用。请帮忙。
谢谢。
简单使用
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id='.$id;
这会起作用
变化自
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=<?php echo $id ?>';
至
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id='.$id;
OR
在开始和结束处添加双 "
。
$uri = "http://nooooo.com/another.php?match_timestamp=0&id=$id";
我知道这个问题已经得到解答,这是一个非常简单的修复,仅此而已。每个人都只是给你一个修复,而没有告诉你你的代码有什么问题。就这样吧
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=<?php echo $id ?>';
这有 2 个问题。
1) 您已经处于 PHP 模式,因此您不需要再次开始和结束 PHP 标签。
2)单引号内没有插值变量,所以要用双引号。
$uri = "http://nooooo.com/another.php?match_timestamp=0&id=$id"; // right
你还提到这个下面的版本也不行
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=$id';
因为它包含了上面提到的第1点而不是第2点。
您需要了解引号在 PHP Single Quoted and Double Quoted
中的工作原理
在这里,您只需将字符串周围的引号更改为
$uri = "http://nooooo.com/another.php?match_timestamp=0&id=$id";
^^ ^^
为此它应该是
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id='.$id;
^^^
是的,还有许多其他方法可以完成此任务..
我有 url,身份证号码是这样的:http://google.org/something.php?id=12345
和php
文件:
<?php
$noid= "0000000000000";
$id=$_GET["id"];
if(!$id)
{
$id=$noid;
}
?>
<?php echo $id ?>
<?php
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=<?php echo $id ?>';
var_dump($uri);
?>
我只需要将 12345(动态数字)放在 $uri
中,但我不知道正确的语法做吧。
刚刚试过类似的东西:
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=$id';
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=.$id.';
但不起作用。请帮忙。
谢谢。
简单使用
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id='.$id;
这会起作用
变化自
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=<?php echo $id ?>';
至
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id='.$id;
OR
在开始和结束处添加双 "
。
$uri = "http://nooooo.com/another.php?match_timestamp=0&id=$id";
我知道这个问题已经得到解答,这是一个非常简单的修复,仅此而已。每个人都只是给你一个修复,而没有告诉你你的代码有什么问题。就这样吧
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=<?php echo $id ?>';
这有 2 个问题。
1) 您已经处于 PHP 模式,因此您不需要再次开始和结束 PHP 标签。
2)单引号内没有插值变量,所以要用双引号。
$uri = "http://nooooo.com/another.php?match_timestamp=0&id=$id"; // right
你还提到这个下面的版本也不行
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id=$id';
因为它包含了上面提到的第1点而不是第2点。
您需要了解引号在 PHP Single Quoted and Double Quoted
中的工作原理在这里,您只需将字符串周围的引号更改为
$uri = "http://nooooo.com/another.php?match_timestamp=0&id=$id";
^^ ^^
为此它应该是
$uri = 'http://nooooo.com/another.php?match_timestamp=0&id='.$id;
^^^
是的,还有许多其他方法可以完成此任务..