<?php
// JSON URL which should be requested
$json_url = 'https://api.feedbin.me/v2/entries.json';
$username = 'username'; // authentication
$password = 'password'; // authentication
// Initializing curl
$ch = curl_init( $json_url );
// Configuring curl options
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => $username . ":" . $password // authentication
);
// Setting curl options
curl_setopt_array( $ch, $options );
// Getting results
$result = curl_exec($ch); // Getting JSON result string
$i=0;
foreach (json_decode($result) as $obj) {
if($i==5) break;
$feedbin_title = $obj->title;
$feedbin_url = $obj->url;
echo '<li><a href="', $feedbin_url, '">', $feedbin_title, '</a></li>';
}
?>
我得到一个 100 个对象的 JSON 结果。我试图将处理的对象限制为前 5 个。为什么这不起作用$i=0; if($i==5) break;
?:)