使用JSON通过http搜索查询

I am sending an API request and want to submit a search term inside the URL:

$query="My Query";
$query_encode= urlencode($query);

$url_json="API_URL".$query_encode
$json = file_get_contents($url_json);

What I want to do is that "My Query" should contain a more complex term like:

"word1 word2" (word3 OR word4) AND word5

My problem is that I want to get the results from the API (database) that match excactly "word1 word2" so I need to somehow send the quoatation marks via http.

Does someone has an idea how I need to set up the content of My Query including the required quotation marks to send a query with the phrase, not just the words

$query="My Query";

if you want to send the quotes then include it in your query.

you set a string value inside quotes in PHP. so what you have right now are not additional quotes that you want to send along in the request but the quotes that will be parsed and removed by PHP.

you should do something like:

$query='"My Query"';

this will result in something like %22My+Query%22

urldecode this later to get back "My Query" as string value.

Put the quotes in the string. urlencode() will take care of encoding them properly. Also, you need ? between the URL and the query parameters, and you probably need to supply a name for the parameter (I'm assuming it's named query in the code below, you need to get the actual parameter from the API specification).

$query = '"word1 word2"';
$query_encode = urlencode($query);
$url_json = "API_URL?query=$query_encode";
$json = file_get_contents($url_json);