1

I am using Amazon API to display dvd and bluray product information on my website. I have the following PHP code that looks up product information based on its ItemID.

$movies = file_get_contents('movies.xml');
$xml = new SimpleXmlElement($movies);

$dvd = $xml->movie->amazon->dvd;
$bluray = $xml->movie->amazon->bluray;

$request = aws_signed_request('co.uk', array(
            'Operation' => 'ItemLookup',
            'ItemId' => '$dvd, $bluray',
            'ResponseGroup' => 'Medium, Offers',
            'MerchantId' => 'All'), $public_key, $private_key, $associate_tag);

I know the following line of code causes the problem:

'ItemId' => '$dvd, $bluray'

I'm not sure how I can assign two variables inside the array wrapped in single quotes.

If I assign direct values to ItemId, then everything works:

$request = aws_signed_request('co.uk', array(
            'Operation' => 'ItemLookup',
            'ItemId' => 'B004Q9SZGC, B004Q9T6CO',
            'ResponseGroup' => 'Medium, Offers',
            'MerchantId' => 'All'), $public_key, $private_key, $associate_tag);

However, I would like to use my $dvd and $bluray variables to look up ItemId stored in the local XML file (movies.xml) rather than hardcode the actual ItemId value inside the array.

1 Answer 1

1

In PHP you can concatenate expressions (e.g. variables and strings) with the . sign.

For example:

'ItemId' => $dvd.', '.$bluray,
Sign up to request clarification or add additional context in comments.

4 Comments

Why would you want to concat?
Thanks for your reply Boaz. I'm very new to PHP and I'm not sure how I can do that properly. Can you give me an example of how concatenation would work in my particular case?
@DarylGill To the best of my understanding, that's basically what the the OP is looking to do.
That's perfect! Thank you for your help Boaz.

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.