Reputation: 391
I use cURL to send requests to REST API and I would like to add a string to created url befeore execute it. This string is not a parameter.
Do you know how can I do that?
Upvotes: 0
Views: 1065
Reputation: 8701
It depends on really what you want to do. If you want to call an URL by appending GET query parameters, you can use string concatenation.
<?php
function get_data($url, $add) {
$url = $url.$add;
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo get_data('http://example.com', '?page=mine');
?>
However, if you want to retrieve a specific URL by sending POST query parameters (e.g. to simulate a form being submitted), you need to implement something like this instead.
Upvotes: 0
Reputation: 12535
It's called string concatenation. In php it can be done: $str = $string1.$string2;
p.s. Always read documentation before asking something. There you can find answers on most of your questions.
Upvotes: 2