// This will remove unwanted characters.
for ($i = 0; $i <= 31; ++$i) {
$result = str_replace(chr($i), "", $result);
}
$result = str_replace(chr(127), "", $result);
// This is the most common part
// Some file begins with 'efbbbf' to mark the beginning of the file. (binary level)
// here we detect it and we remove it, basically it's the first 3 characters
if (0 === strpos(bin2hex($result), 'efbbbf')) {
$result = substr($result, 3);
}
$result = json_decode( $result );
print_r($result);
$collection = Yii::$app->mongodb->getCollection('products');
$result = $collection->aggregate(array(
array(
'$match' => array('user_id' => $filter['user_id']),
),
array(
'$group' => array(
'_id' => array('city_id' => '$city_id'),
'count' => array( '$sum' => 1)
),
),
array(
'$limit' => 20
)
)
);