Home » Php » Using "LIKE" parameter in a php curl request

Using "LIKE" parameter in a php curl request

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a php script that is making a cURL request of a website and I can get data back but I want to be able to send a variable as a LIKE but can’t seem to get that functionality working in the URL.

This is working code with the telephone number entered completely but sometime we only get partial numbers so instead of using value=$telno I need to do something like value LIKE $telno but that doesn’t work.

I get the below error response:

Condition Syntax Error (Line 1, Character 39) – Unexpectedly reached the end of the input when expecting to find a conditional operator.” }

Any suggestions welcomed!

<?php
// Create a cURL session and set to $ch variable
$ch = curl_init();
$companycURL = curl_init();

$header = array(
  'Accept: application/json',
  'Content-Type: application/x-www-form-urlencoded',
  'clientId: **********************************',
  'Authorization: Basic ******************************************'
);
$telno="18002445769";
curl_setopt($companycURL, CURLOPT_URL, "https://www.url.com/company/contacts?childconditions=communicationitems/value=$telno&fields=company/id");
curl_setopt($companycURL, CURLOPT_HTTPHEADER, $header);

curl_setopt($companycURL, CURLOPT_RETURNTRANSFER, 1);

if(curl_exec($companycURL) === false)
{
    echo 'Curl error: ' . curl_error($companycURL);
}
$cpcontents = curl_exec($companycURL);
$myArray = json_decode($cpcontents, true);
$cpid = $myArray[0]['company']['id'];
echo $cpid;
How to&Answers: