error_reporting(E_ALL^E_NOTICE);
ini_set("max_execution_time",300);
header('Content-Type:text/html; charset=utf-8');
try{
$pdo_conn=new PDO('mysql:host=localhost;dbname=iciba_data','root','');
}catch(PDOException $e){
echo 'conn error'.$e->getMessage();
}
$pdo_conn->exec('set names utf8;');
for($i=0;$i>-990;$i--)
{
$time=date("Y-m-d",strtotime("$i day"));
$content=file_get_contents('http://open.iciba.com/dsapi/?date='.$time);
$arr=json_decode($content,$assoc=true);
if(!empty($arr))
{
echo '
';
print_r($arr);
echo '
';$arr[content]=addslashes($arr[content]);
$arr[note]=addslashes($arr[note]);
$arr[translation]=addslashes($arr[translation]);
if(!empty($arr[tags]) and is_array($arr[tags]))
{ $tags='';
$num=0;
foreach($arr[tags] as $tag)
{
$qu_tag="select count(id) from i_tags where id=$tag[id]";
$re_tag=$pdo_conn->query($qu_tag);
$result = $re_tag->fetchColumn();
if($result==0)
{
$ta_ins="insert into i_tags(id,name)values('$tag[id]','$tag[name]')";
$pdo_conn->exec($ta_ins);
}
if($num==0)
{
$tags.=$tag[name];
}else
{
$tags.='|'.$tag[name];
}
$num++;
}
}
$tags=empty($tags)?'':$tags;
$query="insert into i_sentence (sid,tts,content,note,love,translation,picture,picture2,caption,dateline,s_pv,sp_pv,tags,fenxiang_img)values
('$arr[sid]','$arr[tts]','$arr[content]','$arr[note]','$arr[love]','$arr[translation]','$arr[picture]','$arr[picture2]','$arr[caption]','$arr[dateline]','$arr[s_pv]','$arr[sp_pv]','$tags','$arr[fenxiang_img]')";
try{
$pdo_conn->exec($query);
}catch(PDOException $e){
echo 'exec error'.$e->getMessage();
}
}
}