Answer the question
In order to leave comments, you need to log in
Why does the script work on one php server and not on the other?
Hi all.
I've been scratching my head for 4 hours now and can't find the cause.
I have a PHP script for pulling information from the API
<?php
if(preg_match('/^[0-9]*$/',$_GET['id'])!=true) exit('Ошибка');
header("Access-Control-Allow-Origin: ссылка");
$data=json_decode(file_get_contents('ссылка='.$_GET['id']),true);
//print_r($data);
$name=$data['nameRU'];
$nameEN=$data['nameEN'];
$growth=$data['growth'];
$birthday=$data['birthday'];
$age=$data['age'];
$birthplace=$data['birthplace'];
$profession=$data['profession'];
$photo=$data['posterURL'];
$photo='ссылка_'.$data['peopleID'].'.jpg';
$count=0;
for($i=0;$i<count($data['filmography']);$i++) {
if(count($data['filmography'][$i])>1) {
for($j=0;$j<count($data['filmography'][$i]);$j++) $count++;
}
else $count++;
}
$array['name']=(isset($name) AND $name!='') ? $name : '-';
$array['nameEN']=(isset($nameEN) AND $nameEN!='') ? $nameEN : '-';
$array['growth']=(isset($growth) AND $growth!='') ? $growth : '-';
$array['birthday']=(isset($birthday) AND $birthday!='') ? $birthday : '-';
$array['age']=(isset($age) AND $age!='') ? $age : '-';
$array['birthplace']=(isset($birthplace) AND $birthplace!='') ? $birthplace : '-';
$array['profession']=(isset($profession) AND $profession!='') ? $profession : '-';
$array['photo']=(isset($photo) AND $photo!='') ? $photo : '-';
$array['films']=(isset($count) AND $count !='') ? $count : '-';
if($array['name']=='NaN')
echo json_encode(Array('error'=>'Данные не найдены :('));
else {
$data=json_encode($array);
echo $data;
}
?>
Answer the question
In order to leave comments, you need to log in
Probably different servers have different error_reporting settings . Fortunately, it can be set not only through the server configuration, but also during script execution .
In general, the above code fragment looks like a terrible crutch. I would advise you to use the array_key_exists function to check if the corresponding key exists in the array $data
. Something like:
Thus, you are guaranteed to access an array element only if such a key exists in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question