function で json を POST
37行目に PHP Fatal error: Cannot redeclare sendPostData()
と出るのをどのように修正すれば、sendPostData がうまく回りますか。
<?php
$total = 110;
$test = 2;
for ( $i = 0; $i <= ceil($total/100); $i++){
$data = array (
"filters" => array (
array (
"field" => "live_status",
"type" => "equal",
"value" => "past",
),
array (
"field" => "start_time",
"from" => "2014-03-12 00:00:00",
"to" => "2014-03-13 00:00:00",
"type" => "range",
)
),
"from" => $test*$i,
"issuer" => "apiguide",
"join" => array ( 0 => "cmsid", 1 => "title", 2 => "community_id", 3 => "start_time", 4 => "live_end_time", 5 => "comment_counter", 6 => "score_timeshift_reserved", 7 => "provider_type", 8 => "tags", 9 => "member_only"),
"order" => "desc",
"query" => "一般(その他)",
"reason" => "ma9",
"search" => array ( "tags" ),
"service" => array ( "live" ),
"size" => $test,
"sort_by" => "_live_recent",
);
$encoded = json_encode($data, JSON_UNESCAPED_UNICODE);
$url_send ="http://api.search.nicovideo.jp/api/";
function sendPostData($url, $post){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json; charset=UTF-8'));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
echo " " . sendPostData($url_send, $encoded);
}
?>