简体   繁体   English

API-PHP变量

[英]API - PHP Variables

We are trying to get part of a API Working and we are getting a litle stuck 我们正试图让API工作的一部分,我们正在陷入困境

$armory = new BattlenetArmory('EU','Azjol-Nerub'); //ex. ('US', 'Exodar')

Above is part of the code within the Api script and what we are looking for is a way to "populate" the EU and Azjol-Nerub parts dynamically so hopefully we could have another page feeding the 2 variables into this script. 上面是Api脚本中代码的一部分,我们正在寻找一种动态地“填充” EU和Azjol-Nerub部分的方法,因此希望我们可以在另一个页面中将2个变量输入该脚本中。

Hardcoded the script works without a sniff of a problem .... However 硬编码脚本的工作原理没有任何问题....但是

I dont know if this even works but this is what i ventured as a newbie and tried : 我不知道这是否有效,但这是我作为一个新手冒险尝试:

$test='EU'; 
$armory = new BattlenetArmory('.$test.','Azjol-Nerub'); //ex. ('US', 'Exodar')

$test='EU'; 
$armory = new BattlenetArmory('<?php echo $test ?>','Azjol-Nerub'); //ex. ('US', 'Exodar')

And it broke 它打破了

Im not too sure how to get around this .. even if there is a way to get around it 我不太确定如何解决这个问题..即使有办法绕过它

Im hoping someone might be able to lend me a hand with this if possible and for me to possibly learn as to where im going wrong 我希望有人可以在可能的情况下帮助我,让我了解我在哪里出错

thanks 谢谢

... ...

$test='EU'; 
$armory = new BattlenetArmory($test, 'Azjol-Nerub'); //ex. ('US', 'Exodar')

You need to specify the variable OUTSIDE the quotes 您需要在引号中指定变量OUTSIDE

$armory = new BattlenetArmory($test,'Azjol-Nerub');

Or, if you have mod_string_replace enabled, you can do 或者,如果启用了mod_string_replace,则可以执行

$armory = new BattlenetArmory("$test",'Azjol-Nerub'); 

This will replace the $test inside the double quotes with the value of $test. 这会将双引号内的$ test替换为$ test的值。 This is unnecessary, because it will add useless processing requirements to your page, but it is useful if you want to create a string out of many variables. 这是不必要的,因为它将为您的页面增加无用的处理要求,但是如果您想从许多变量中创建一个字符串,这将非常有用。 eg 例如

$name="John Doe";
$age=35;
$country="USA";

$message="$name, age $age, lives in $country"; //Gives John Doe, age 35, lives in USA

Just to clear up the understanding here, dots are for concatenating strings. 为了清除这里的理解,点用于连接字符串。 Like + in JS and & in VB. 像JS和&VB中的+。

$name = 'John';
echo 'hello there ' . $name . ', how are you?';

Weirdly in PHP you can put variables inside strings that are enclosed by double quotes and they will be replaced by values - so this will work (with a very slight performance drop). 很奇怪,在PHP中你可以将变量放在用双引号括起的字符串中,它们将被值替换 - 所以这将起作用(性能下降很小)。

$name = 'John';
echo "hello there $name, how are you?";

The thing was never going to work, PHP loads up all code between those tags at the start, parses them and then begins to do its job. 事情永远不会起作用,PHP在开始时加载这些标记之间的所有代码,解析它们然后开始完成它的工作。 It has no meaning after that. 此后没有任何意义。

So the answer to your question is as someone else said above - just thought I'd explain: 所以你的问题的答案就像上面有人说的那样 - 只是想我会解释:

$test='EU'; 
$armory = new BattlenetArmory($test, 'Azjol-Nerub'); //ex. ('US', 'Exodar')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM