0

I have a token for a specific ID number which is 494

$url = api.pipedrive.com/v1/deals/494/products?start=0&api_token=7ecb71622dadd2faae2732bfe73b09381150c967;

I want to change the number 494 to any number.

I've made an illogical code to begin with.

Any guide on how to do this?

$url = "https://api.pipedrive.com/v1/deals/";
$id = 494;
$api = "/products?start=0&api_token=7ecb71622dadd2faae2732bfe73b09381150c967";

$response = file_get_contents($url+$id+$api);
echo $response;

$object = json_decode($response, true);

I got the errorL

Warning: file_get_contents(494): failed to open stream: No such file or directory

9
  • Could you clarify what problem you want to solve? Because it just sounds like you want to redeclare variables: $id = 123; Commented Oct 2, 2016 at 15:10
  • + isn't used for concatenation in PHP. Commented Oct 2, 2016 at 15:14
  • @Thomas yeah, I wanted to be able to change the $id dynamically and call the complete token the same as the first $url above Commented Oct 2, 2016 at 15:14
  • @Devon yeah I figured too. Do you know anyway to call the $url, $id, and $api in file_get_contents? Commented Oct 2, 2016 at 15:16
  • 1
    @AntheaMarie the PHP manual is useful: php.net/manual/en/language.operators.string.php Commented Oct 2, 2016 at 15:17

2 Answers 2

2

You are using '+' operator to concatenate. Which sums two variable. You need to use concatenation operator ('.') not '+'

$url = $url.$id.$api;
Sign up to request clarification or add additional context in comments.

Comments

0

In PHP, . is used for string concatenation. Also you can use the .= to append a string to a string variable. Example:

$str = "Hello";
$str2 = $str . "Anthea"; // $str2 = "Hello Anthea"

Or

$str = "Hello";
$str .= "Anthea"; // $str = "Hello Anthea"

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.