1

We are trying to get part of a API Working and we are getting a litle stuck

$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.

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

1
  • Seriously, this made me laugh - thank you. =) Commented Nov 15, 2011 at 6:21

3 Answers 3

3

...

$test='EU'; 
$armory = new BattlenetArmory($test, 'Azjol-Nerub'); //ex. ('US', 'Exodar')
Sign up to request clarification or add additional context in comments.

Comments

0

You need to specify the variable OUTSIDE the quotes

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

Or, if you have mod_string_replace enabled, you can do

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

This will replace the $test inside the double quotes with the value of $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. e.g.

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

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

Comments

0

Just to clear up the understanding here, dots are for concatenating strings. Like + in JS and & in 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).

$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. 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')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.