Home  >  Article  >  php教程  >  php金山词霸api

php金山词霸api

PHP中文网
PHP中文网Original
2016-05-25 16:58:402009browse

php金山词霸接口 每日一句获取数据

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();
		}
	}
	
}

                   

 以上就是php金山词霸api的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php cloneNext article:php压缩css和js类