Below mentioned elastic search query which is working fine if we hit it directly,
JavaScript
x
{
"query": {
"query_string": {
"query": ""testtext/123""
}
}
}
In PHP array how to pass the above-mentioned query with backslashes. I tried the below code which gives an error response.
JavaScript
$query = array(
"query"=>[
"query_string"=> [
"query"=>"".$string.""
]
]
);
Error is:
syntax error, unexpected ” (T_NS_SEPARATOR)
Advertisement
Answer
is an escape character, you need to escape that itself otherwise it escapes the second "
so PHP thinks the strings are unfinished. You need to resolve the syntax error and also ensure the the second quote mark is actually part of the string, not a PHP delimiter.
The simplest way actually would be to use single quotes for the string delimiter in PHP:
JavaScript
$query = array(
"query"=>[
"query_string"=> [
"query"=>'"'.$string.'"'
]
]
);