I have an api in one of my sites. When I try to fetch contents width file_get_contents
an error occures.
I have tested the url in the browser and it's okay.
Here is my url dilox.ir/category/مجله-ماشین/?json=1
and here is my php code
$cat = 'مجله-ماشین';
$json = file_get_contents('http://dilox.ir/category/' . $cat . '/json=1&count=10&page=' . $page);
after I execute my code. I face with this error
{ "name":"PHP Notice",
"message":"Trying to get property of non-object",
"code":8,
"type":"yii\\base\\ErrorException",
"file":"C:\\xampp\\htdocs\\pkhodro\\controllers\\ApiController.php",
"line":142,
"stack-trace":["#0 C:\\xampp\\htdocs\\pkhodro\\controllers\\ApiController.php(142): yii\\base\\ErrorHandler->handleError(8, 'Trying to get p...', 'C:\\\\xampp\\\\htdocs...', 142, Array)",
"#1 [internal function]: app\\controllers\\ApiController->actionGet_magazines(1)",
"#2 C:\\xampp\\htdocs\\pkhodro\\vendor\\yiisoft\\yii2\\base\\InlineAction.php(55): call_user_func_array(Array, Array)",
"#3 C:\\xampp\\htdocs\\pkhodro\\vendor\\yiisoft\\yii2\\base\\Controller.php(154): yii\\base\\InlineAction->runWithParams(Array)",
"#4 C:\\xampp\\htdocs\\pkhodro\\vendor\\yiisoft\\yii2\\base\\Module.php(454): yii\\base\\Controller->runAction('get_magazines', Array)",
"#5 C:\\xampp\\htdocs\\pkhodro\\vendor\\yiisoft\\yii2\\web\\Application.php(87): yii\\base\\Module->runAction('api/get_magazin...', Array)",
"#6 C:\\xampp\\htdocs\\pkhodro\\vendor\\yiisoft\\yii2\\base\\Application.php(375): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))",
"#7 C:\\xampp\\htdocs\\pkhodro\\web\\index.php(12): yii\\base\\Application->run()","#8 {main}"
]
}
it shows that it can't read the url. Same code is executing successfully for a category without hyphen
Please see this Edit
I tested my code. file_get_contents
return json for me, but json_decode can't decode the returned json and cause the error