php Curl: Error:Illegal characters found in URL

  curl, php

i’m getting this error Error:Illegal characters found in URL, i know this error is on the part that creates array from input lines, it’s probably a invisible character that is causing it, i inspected with var_dump and it’s showing one character more than the input, but can’t see the character, it’s probably invisible.

var_dump:

array(5) {
  [0]=>
  string(11) "150812.mp4"
  [1]=>
  string(11) "150811.mp4"
  [2]=>
  string(11) "150810.mp4"
  [3]=>
  string(11) "150372.mp4"
  [4]=>
  string(10) "150369.mp4"
}

code:

$token = "hidden";


if (!isset($_POST['comment'])) {
    
    echo "
    <form method='post' action='./'>
    <textarea name='comment' rows='20' cols='60'></textarea>
    <input type='submit' />
    </form>
    ";

} else {

// create array from input lines
$array_items = explode("n", $_POST['comment']);

   foreach ($array_items as $file_name) {

        #-----------------------------------------------------------
        #--                     GET FILE ID                      --#
        #-----------------------------------------------------------

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, "https://api.box.com/2.0/search?query=$file_name");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');


        $headers = array();
        $headers[] = "Authorization: Bearer $token";
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);

        $arr = json_decode($result, true);
        extract($arr);
        
        // file id
        $file_id = $arr["entries"][0]["id"];
   }
}

Source: Ask PHP

LEAVE A COMMENT