Php 分析错误:语法错误,意外';旋度设置选项';(T_字符串)
我看了一段youtube视频,发现了这些代码 我的php文件index.phpPhp 分析错误:语法错误,意外';旋度设置选项';(T_字符串),php,json,curl,Php,Json,Curl,我看了一段youtube视频,发现了这些代码 我的php文件index.php <?php //initialize session $ch = curl_init(); //set the URL $url = "http://localhost:81/data.php" //set options curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_set
<?php
//initialize session
$ch = curl_init();
//set the URL
$url = "http://localhost:81/data.php"
//set options
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
//execution
$json=curl_exec($ch);
//close
curl_close($ch);
//decode the json
$json=json_decode($json, true);
//loop through the results
for($i=0;$i<['Metadata']['TotalResults'];$i++){
echo "JSON : <b>First Name = </b>". $json['Result'][$i]["FirstName"]." , <b>Last Name = </b>".$json['Result'][$i]["LastName"];
}
?>
我的json文件data.php
<?php
//metadata which will contain how many resukts we have
$meta_array['TotalResults'] = 1;
$metadata = '{"Metadata" : ';
$metadata .= json_encode($meta_array). ',';
//the data
$array["FirstName"] = 'Gary';
$array["LastName"] = 'George';
$data[] = $array;
//json encode the array
$json_encoded = utf8_encode(json_encode($data));
echo $metadata . ' "Result" : '.$json_encoded. '}' ;
exit();
?>
我不断得到上述错误
我对jason和curl不熟悉。
请帮我解决我的问题
提前感谢:)我看不到url后面有分号
$url = "http://localhost:81/data.php";
^ it is missing
在代码块中,您使用的是$i
$i<$your_array['Metadata']['TotalResults']