WEB服务数据纯静态实现
有时有有一些不常变动的,但是访问比较频繁的可以缓存起来,如果时常比较长的就更可以存成文本形式。
示例:http://nba2k.qq.com/act/a20140910player/index.shtml
下面简单记录下操作的流程和步骤:
这是一个NBA球员库的页面,里面有当今NBA在役的所有球员、和球队的资料。
第一步:对源CSV数据处理
数据文件分为四个:非王朝球员、王朝球员、球队、王朝球员能力(王朝球员是可以成长的类似从B+ 升级到 S)
其中四个文件内容如下
球队
iconID,球队中文名,综合,进攻,防守,能量值,nba对抗赛解锁条件,首发-PG,首发-SG,首发-SF,首发-PF,首发-C,替补,替补,替补,替补,替补,替补,替补,球馆中文名,教练名,教练介绍,创立年份,球队介绍,东西部冠军次数,总冠军次数,历史球星 iconID,name,average,offense,defense,power,matchedeblock,playerIDforPG,playerIDforSG,playerIDforSF,playerIDforPF,playerIDforC,backupPlayers1,backupPlayers2,backupPlayers3,backupPlayers4,backupPlayers5,backupPlayers6,backupPlayers7,stadium,coachName,coachIntro,foundDate,teamIntro,divisionChampionTimes,finalChampionTimes,historicalStars 5001,76人,73,72,74,0,0,伊斯.史密斯,贾森.理查德森,杰拉米.格兰特,卢克.巴莫特,诺伦斯.诺尔,托马斯.罗宾逊,霍里斯.汤普森,罗伯特.卡温顿,托尼.罗特恩,雅卡尔.桑普森,乔尔.恩比德,以赛亚.迦南,富国中心球馆 ,布雷特.布朗,布朗曾从2002年开始担任波波维奇的助理教练,并一起执教过7个赛季。现在他正与管理团队重建这支球队。,1939,"费城76人前身叫做锡拉库扎国民队,是NBA联盟的""开国元老""之一,76人的取名是为了纪念1776年美国独立宣言在费城签订宣布。 76人一直是一支伟大的球队,如果你一定要问为什么,那么就请看这里有过哪些伟大的球员。第一个为76人队注入激情的球员是集速度、高度、力量和技术于一身的篮坛历史全才张伯伦,而后""J博士""朱利叶斯.欧文和天才中锋摩西.马龙给76人带来了再次辉煌,76人34号的退役号码则属于大名鼎鼎的查尔斯.巴克利。 而说到近代的76人,相信大家都难以忘记那个身高不高但是疾如闪电的""答案"":艾佛森。",9,3,威尔特.张伯伦,比利.康宁汉,朱利叶斯.欧文,摩西.马龙,查尔斯.巴克利,阿伦.艾弗森,杰里.斯塔克豪斯。
球员
球员id,球员avatar-id,品质,球员名字-中文,球员昵称,第一位置,第二位置,工资,号码,身高(cm),体重(kg),球队,能力特长,球员等级,能力评价,总冠军,全明星,MVP,得分王,助攻王,篮板王,一句话攻略,球星介绍,视频名字,视频图,视频链接,现役球星/历史球星 playerID,avartarID,quality,name,nickname,firstPosition,secondPosition,salary,number,height,weight,teamID,speciality,level,rank,championTimes,allStarTimes,mvpTimes,scoreTimes,assistTimes,reboundTimes,strategy,playerInfo,videoName,videoPic,videoSrc,isWork 4001,1607,蓝,朱.霍利迪,,PG,—,2000,11,193,93,鹈鹕,无,,A+,,1,,,,,,"最终评价为A+ 瘦长型球员,节奏、控球能力以及防守意识都是他的优点所在。他的双手都可以攻篮,从发动进攻到出手,双手几乎不分主次。 ",,,,现役球星
球员能力
球员ID,球员名,等级,近投,中投,远投,靠打,扣篮,控球,传球,盖帽,速度,篮板,防守,力量,球员评价 playerID,name,level,jintou,zhongtou,yuantou,kaoda,koulan,kongqiu,chuanqiu,gaimao,sudu,lanban,fangshou,liliang,rank 4001,朱.霍利迪,1,122,133,132,131,136,43,140,64,40,114,114,138,B
第一步:把这些CSV 数据处理下、你可以存储到数据库里面或者转换成PHP数组,以方便调用、这里我存储到PHP数组里面关键函数如下
把数据组装成数组来用 第一步: $feiwangchaoqiuyuan = './csv/feiwangchaoqiuyuan.csv';//非王朝球员 $wangchaoqiuyuan = './csv/wangchaoqiuyuan.csv'; //王朝球员 $wangchaoqiuyuannengli = './csv/wangchaoqiuyuannengli.csv'; //王朝球员能力 $qiudui = './csv/qiudui.csv'; //球队 //'isDynasty': '0', 是否是王朝 $D_nengli = getData($wangchaoqiuyuannengli); writeToPHP(getData($feiwangchaoqiuyuan),'./php/feiwangchaoqiuyuan.php'); //生成PHP数组文件 非王朝球员 ID 为主键 writeToPHP(getData($wangchaoqiuyuan),'./php/wangchaoqiuyuan.php');//生成PHP数组文件 王朝球员 ID 为主键 writeToPHP(getData($feiwangchaoqiuyuan,3),'./php/feiwangchaoqiuyuan_cn.php');//生成PHP数组文件非王朝球员 中文名 为主键 writeToPHP(getData($wangchaoqiuyuan,3),'./php/wangchaoqiuyuan_cn.php');//生成PHP数组文件 王朝球员 中文名 为主键 writeToPHP(getData($wangchaoqiuyuannengli,0,true),'./php/wangchaoqiuyuannengli.php');//生成PHP数组文件 王朝球员能力 ID 为主键 writeToPHP(getData($qiudui),'./php/qiudui.php'); //生成PHP数组文件 球队 ID 为主键 function writeToPHP($data,$file){ if(strpos($file, '.php') === false) $file = $file.'.php'; file_exists($file) or touch($file); $str = var_export($data,TRUE); $str = "<?php\r\n return ".$str.";\r\n"; file_put_contents($file, $str); } function getData($file_name,$priKey=0,$recursion = false){ $baseDataHandle = fopen($file_name, "r"); $data = array(); $keys = fgetcsv($baseDataHandle); $keys = fgetcsv($baseDataHandle);//第二次是对应的键值 while (!feof($baseDataHandle)) { $tmp_value = fgetcsv($baseDataHandle); $tmp_data = array_combine($keys, $tmp_value); if($recursion){ $data[$tmp_value[$priKey]][] = $tmp_data; } else { $data[$tmp_value[$priKey]] = $tmp_data; } } fclose($baseDataHandle); return $data; }
其中关键函数var_export($data,TRUE),这个函数可以把数组按照PHP格式输出,然后我们创建文件保存下来
然后我们把这些基本的数据处理成我们想要的格式,一共需要三个文件
indexData.js 首页的球员数据,这需要所有的球员,但是不需要球员的全部数据,就是基本信息
playerData.js 这个是球员详情需要的数据
teamData.js 这个是球队的数据、
第一步:引入我们的PHP文件
ini_set("display_errors", 1); error_reporting(E_ALL ^ E_NOTICE); //http://demo.qq.com/kefirzhang/dev_root/nba2k/a20140910player/ //生成json文件 第二步 $feiwangchaoqiuyuan = require('./php/feiwangchaoqiuyuan.php'); //生成PHP数组文件 非王朝球员 ID 为主键 $wangchaoqiuyuan = require('./php/wangchaoqiuyuan.php');//生成PHP数组文件 王朝球员 ID 为主键 $feiwangchaoqiuyuan_cn = require('./php/feiwangchaoqiuyuan_cn.php');//生成PHP数组文件非王朝球员 中文名 为主键 $wangchaoqiuyuan_cn = require('./php/wangchaoqiuyuan_cn.php');//生成PHP数组文件 王朝球员 中文名 为主键 $wangchaoqiuyuannengli = require('./php/wangchaoqiuyuannengli.php');//生成PHP数组文件 王朝球员能力 ID 为主键 $qiudui = require('./php/qiudui.php'); //生成PHP数组文件 球队 ID 为主键
第二步:生成Json 数据,因为PHP版本比较低Json_encode 会造成中文丢失的问题,所以这边直接吐到浏览器上面。另存解决
//第2.1 生成 indexData.js文件 $indexDataFile = 'indexData.js'; $indexData = array(); echo "var players = [\r\n"; foreach ($feiwangchaoqiuyuan as $key=>$value){ echo $tmp_str = <<<STR { 'playerID': '{$value['playerID']}', 'avartarID': '{$value['avartarID']}', 'quality': '{$value['quality']}', 'name': '{$value['name']}', 'nickname': '{$value['nickname']}', 'firstPosition': '{$value['firstPosition']}', 'secondPosition': '{$value['secondPosition']}', 'isDynasty': '0', 'number': '{$value['number']}', 'height': '{$value['height']}', 'weight': '{$value['weight']}', 'teamID': '{$value['teamID']}', 'rank': '{$value['rank']}', 'aHStar': '{$value['isWork']}', 'championTimes': '{$value['championTimes']}', 'allStarTimes': '{$value['allStarTimes']}', 'mvpTimes': '{$value['mvpTimes']}', 'scoreTimes': '{$value['scoreTimes']}', 'assistTimes': '{$value['assistTimes']}', 'reboundTimes': '{$value['reboundTimes']}' }, STR; } foreach ($wangchaoqiuyuan as $key=>$value){ echo $tmp_str = <<<STR { 'playerID': '{$value['playerID']}', 'avartarID': '{$value['avartarID']}', 'quality': '{$value['quality']}', 'name': '{$value['name']}', 'nickname': '{$value['nickname']}', 'firstPosition': '{$value['firstPosition']}', 'secondPosition': '{$value['secondPosition']}', 'isDynasty': '1', 'number': '{$value['number']}', 'height': '{$value['height']}', 'weight': '{$value['weight']}', 'teamID': '{$value['teamID']}', 'rank': '{$value['rank']}', 'aHStar': '{$value['isWork']}', 'championTimes': '{$value['championTimes']}', 'allStarTimes': '{$value['allStarTimes']}', 'mvpTimes': '{$value['mvpTimes']}', 'scoreTimes': '{$value['scoreTimes']}', 'assistTimes': '{$value['assistTimes']}', 'reboundTimes': '{$value['reboundTimes']}' }, STR; } echo "\r\n]"; die;
//第2.2 生成 playerData.js文件 $playerDataFile = 'playerData.js'; $indexDataFile = 'indexData.js'; $indexData = array(); echo "var play = {\r\n"; foreach ($feiwangchaoqiuyuan as $key=>$value){ $value['playerInfo'] = str_replace("\r\n", '', $value['playerInfo']); $value['playerInfo'] = str_replace("\n", '', $value['playerInfo']); $value['playerInfo'] = str_replace("\r", '', $value['playerInfo']); //$abilities = getAbilities($value['playerID']); echo $tmp_str = <<<STR '{$value['playerID']}':{ 'playerID': '{$value['playerID']}', 'avartarID': '{$value['avartarID']}', 'quality': '{$value['quality']}', 'name': "{$value['name']}", 'nickname': "{$value['nickname']}", 'firstPosition': '{$value['firstPosition']}', 'secondPosition': '{$value['secondPosition']}', 'isDynasty': '0', 'salary': '{$value['salary']}', 'number': '{$value['number']}', 'height': '{$value['height']}', 'weight': '{$value['weight']}', 'teamID': '{$value['teamID']}', 'speciality': '{$value['speciality']}', 'rank': '{$value['rank']}', 'championTimes': '{$value['championTimes']}', 'allStarTimes': '{$value['allStarTimes']}', 'mvpTimes': '{$value['mvpTimes']}', 'scoreTimes': '{$value['scoreTimes']}', 'assistTimes': '{$value['assistTimes']}', 'reboundTimes': '{$value['reboundTimes']}', 'strategy': '{$value['strategy']}', 'playerInfo': '{$value['playerInfo']}', 'videoName': '{$value['videoName']}', 'videoPic': '{$value['videoPic']}', 'videoSrc': '{$value['videoSrc']}', 'abilities':{ 'jintou': '{$value['jintou']}', 'zhongtou': '{$value['zhongtou']}', 'yuantou': '{$value['yuantou']}', 'kaoda': '{$value['kaoda']}', 'koulan': '{$value['koulan']}', 'kongqiu': '{$value['kongqiu']}', 'chuanqiu': '{$value['chuanqiu']}', 'gaimao': '{$value['gaimao']}', 'sudu': '{$value['sudu']}', 'lanban': '{$value['lanban']}', 'fangshou': '{$value['fangshou']}', 'liliang': '{$value['liliang']}' } }, STR; } foreach ($wangchaoqiuyuan as $key=>$value){ $value['playerInfo'] = str_replace("\r\n", '', $value['playerInfo']); $value['playerInfo'] = str_replace("\n", '', $value['playerInfo']); $value['playerInfo'] = str_replace("\r", '', $value['playerInfo']); $abilities = getAbilities($value['playerID']); echo $tmp_str = <<<STR '{$value['playerID']}':{ 'playerID': '{$value['playerID']}', 'avartarID': '{$value['avartarID']}', 'quality': '{$value['quality']}', 'name': "{$value['name']}", 'nickname': "{$value['nickname']}", 'firstPosition': '{$value['firstPosition']}', 'secondPosition': '{$value['secondPosition']}', 'isDynasty': '1', 'salary': '{$value['salary']}', 'number': '{$value['number']}', 'height': '{$value['height']}', 'weight': '{$value['weight']}', 'teamID': '{$value['teamID']}', 'speciality': '{$value['speciality']}', 'rank': '{$value['rank']}', 'championTimes': '{$value['championTimes']}', 'allStarTimes': '{$value['allStarTimes']}', 'mvpTimes': '{$value['mvpTimes']}', 'scoreTimes': '{$value['scoreTimes']}', 'assistTimes': '{$value['assistTimes']}', 'reboundTimes': '{$value['reboundTimes']}', 'strategy': '{$value['strategy']}', 'playerInfo': '{$value['playerInfo']}', 'videoName': '{$value['videoName']}', 'videoPic': '{$value['videoPic']}', 'videoSrc': '{$value['videoSrc']}', 'abilities':{$abilities} }, STR; } echo "\r\n}"; function getAbilities($playerID){ $str = "{\r\n"; global $wangchaoqiuyuannengli; $length = count($wangchaoqiuyuannengli[$playerID]); $i = 1; foreach ($wangchaoqiuyuannengli[$playerID] as $key=>$value){ $doat = ''; if($i == $length) { $doat = ''; } else { $doat = ','; } $tmp_str = <<<STR '{$value['level']}':{ 'jintou': '{$value['jintou']}', 'zhongtou': '{$value['zhongtou']}', 'yuantou': '{$value['yuantou']}', 'kaoda': '{$value['kaoda']}', 'koulan': '{$value['koulan']}', 'kongqiu': '{$value['kongqiu']}', 'chuanqiu': '{$value['chuanqiu']}', 'gaimao': '{$value['gaimao']}', 'sudu': '{$value['sudu']}', 'lanban': '{$value['lanban']}', 'fangshou': '{$value['fangshou']}', 'liliang': '{$value['liliang']}', 'rank': '{$value['rank']}' }{$doat} STR; $str.= $tmp_str; $i++; } return $str."\r\n}"; }
//第2.3 生成 teamData.js文件 $Tools = new tools($feiwangchaoqiuyuan_cn,$wangchaoqiuyuan_cn); echo "var team = {\r\n"; foreach ($qiudui as $key=>$value){ $value['teamIntro'] = str_replace("\r\n", '', $value['teamIntro']); $value['teamIntro'] = str_replace("\n", '', $value['teamIntro']); $value['teamIntro'] = str_replace("\r", '', $value['teamIntro']); echo <<<STR '{$value['iconID']}':{ 'iconID':'{$value['iconID']}', 'name':'{$value['name']}', 'abilities':{ 'average':'{$value['average']}', 'offense':'{$value['offense']}', 'defense':'{$value['defense']}', 'power':'{$value['power']}', 'matchedeblock':'{$value['matchedeblock']}' }, 'startingPlayers':{ 'playerIDforPG':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['playerIDforPG'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['playerIDforPG'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['playerIDforPG'],'name')}', 'quality':'{$Tools->getPlayerInfoFromCn($value['playerIDforPG'],'quality')}' }, 'playerIDforSG':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['playerIDforSG'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['playerIDforSG'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['playerIDforSG'],'name')}', 'quality':'{$Tools->getPlayerInfoFromCn($value['playerIDforSG'],'quality')}' }, 'playerIDforSF':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['playerIDforSF'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['playerIDforSF'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['playerIDforSF'],'name')}', 'quality':'{$Tools->getPlayerInfoFromCn($value['playerIDforSF'],'quality')}' }, 'playerIDforPF':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['playerIDforPF'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['playerIDforPF'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['playerIDforPF'],'name')}', 'quality':'{$Tools->getPlayerInfoFromCn($value['playerIDforPF'],'quality')}' }, 'playerIDforC':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['playerIDforC'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['playerIDforC'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['playerIDforC'],'name')}', 'quality':'{$Tools->getPlayerInfoFromCn($value['playerIDforC'],'quality')}' } }, 'backupPlayers':{ '{$Tools->getPlayerInfoFromCn($value['backupPlayers1'],'playerID')}':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers1'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers1'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['backupPlayers1'],'name')}', 'number':'{$Tools->getPlayerInfoFromCn($value['backupPlayers1'],'number')}', 'firstPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers1'],'firstPosition')}', 'secondPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers1'],'secondPosition')}', 'rank':'{$Tools->getPlayerInfoFromCn($value['backupPlayers1'],'rank')}' }, '{$Tools->getPlayerInfoFromCn($value['backupPlayers2'],'playerID')}':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers2'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers2'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['backupPlayers2'],'name')}', 'number':'{$Tools->getPlayerInfoFromCn($value['backupPlayers2'],'number')}', 'firstPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers2'],'firstPosition')}', 'secondPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers2'],'secondPosition')}', 'rank':'{$Tools->getPlayerInfoFromCn($value['backupPlayers2'],'rank')}' }, '{$Tools->getPlayerInfoFromCn($value['backupPlayers3'],'playerID')}':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers3'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers3'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['backupPlayers3'],'name')}', 'number':'{$Tools->getPlayerInfoFromCn($value['backupPlayers3'],'number')}', 'firstPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers3'],'firstPosition')}', 'secondPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers3'],'secondPosition')}', 'rank':'{$Tools->getPlayerInfoFromCn($value['backupPlayers3'],'rank')}' }, '{$Tools->getPlayerInfoFromCn($value['backupPlayers4'],'playerID')}':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers4'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers4'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['backupPlayers4'],'name')}', 'number':'{$Tools->getPlayerInfoFromCn($value['backupPlayers4'],'number')}', 'firstPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers4'],'firstPosition')}', 'secondPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers4'],'secondPosition')}', 'rank':'{$Tools->getPlayerInfoFromCn($value['backupPlayers4'],'rank')}' }, '{$Tools->getPlayerInfoFromCn($value['backupPlayers5'],'playerID')}':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers5'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers5'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['backupPlayers5'],'name')}', 'number':'{$Tools->getPlayerInfoFromCn($value['backupPlayers5'],'number')}', 'firstPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers5'],'firstPosition')}', 'secondPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers5'],'secondPosition')}', 'rank':'{$Tools->getPlayerInfoFromCn($value['backupPlayers5'],'rank')}' }, '{$Tools->getPlayerInfoFromCn($value['backupPlayers6'],'playerID')}':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers6'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers6'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['backupPlayers6'],'name')}', 'number':'{$Tools->getPlayerInfoFromCn($value['backupPlayers6'],'number')}', 'firstPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers6'],'firstPosition')}', 'secondPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers6'],'secondPosition')}', 'rank':'{$Tools->getPlayerInfoFromCn($value['backupPlayers6'],'rank')}' }, '{$Tools->getPlayerInfoFromCn($value['backupPlayers7'],'playerID')}':{ 'playerID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers7'],'playerID')}', 'avartarID':'{$Tools->getPlayerInfoFromCn($value['backupPlayers7'],'avartarID')}', 'name':'{$Tools->getPlayerInfoFromCn($value['backupPlayers7'],'name')}', 'number':'{$Tools->getPlayerInfoFromCn($value['backupPlayers7'],'number')}', 'firstPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers7'],'firstPosition')}', 'secondPosition':'{$Tools->getPlayerInfoFromCn($value['backupPlayers7'],'secondPosition')}', 'rank':'{$Tools->getPlayerInfoFromCn($value['backupPlayers7'],'rank')}' } }, 'stadium':'{$value['stadium']} ', 'coachName':'{$value['coachName']}', 'coachIntro':'{$value['coachIntro']}', 'foundDate':'{$value['foundDate']}', 'teamIntro':'{$value['teamIntro']}', 'divisionChampionTimes':'{$value['divisionChampionTimes']}', 'finalChampionTimes':'{$value['finalChampionTimes']}', 'historicalStars':'{$value['historicalStars']}' }, STR; } echo "\r\n}"; class tools{ public $wangchaoqiuyuan_cn; public $feiwangchaoqiuyuan_cn; public function __construct($feiwangchaoqiuyuan_cn,$wangchaoqiuyuan_cn){ $this->feiwangchaoqiuyuan_cn = $feiwangchaoqiuyuan_cn; $this->wangchaoqiuyuan_cn = $wangchaoqiuyuan_cn; } function getPlayerInfoFromCn($cnname,$key){ $cnname = trim($cnname); $key = trim($key); if($this->feiwangchaoqiuyuan_cn[$cnname]) { return $this->feiwangchaoqiuyuan_cn[$cnname][$key]; } else { return $this->wangchaoqiuyuan_cn[$cnname][$key]; } } } die();
吐到页面上以后分别保存成js 文件就行了
数据到这一步就处理好了!
示例可以参考正式的,也可以参考
www.jaafee.cn/demo/nba2k/a20140910player/index.shtml
前端的JS主要是遍历匹配然后替换内容核心代码如下
var PlayClass={ "curTeam":'', "curQuality":"", "curPosition":"", "curaHStar":"", "curSearchKey":"", "playData":[], "selectArr":[], "playerModel":function(){ return players; }, "playerControl":function(selectTeam,selectRank,selectPosition,selectAHStar,selectSearchKey){ this.curTeam = selectTeam; this.curQuality = selectRank; this.curPosition = selectPosition; this.curaHStar = selectAHStar; this.curSearchKey = selectSearchKey; this.selectArr = []; this.playData = this.playerModel(); var _playLen = this.playData.length; if(this.curTeam=='' && this.curQuality=='' && this.curPosition=='' && this.curaHStar=='' && this.curSearchKey==''){ this.selectArr = this.playData; } else { for(var i=0;i<_playLen;i++){ if((this.curTeam!='' && this.curTeam!=this.playData[i].teamID) ||(this.curQuality!='' && this.curQuality!=this.playData[i].quality) ||(this.curPosition!='' && this.curPosition!=this.playData[i].firstPosition && this.curPosition!=this.playData[i].secondPosition) ||(this.curaHStar!='' && this.curaHStar!=this.playData[i].aHStar) ||(this.curSearchKey!='' && this.playData[i].name.indexOf(this.curSearchKey) == -1 && this.playData[i].nickname.indexOf(this.curSearchKey) == -1)){ continue; } this.selectArr.push(this.playData[i]); } } this.playerView(); }, "playerView":function(){ var playerlist = ''; var bg = {"蓝":"a","紫":"s","绿":"b","白":"c"}; for(var i=0;i<this.selectArr.length;i++){ playerlist += '<li class="'+bg[this.selectArr[i].quality]+'"><a href="http://nba2k.qq.com/act/a20140910player/player.shtml?playerID='+this.selectArr[i].playerID+'" class="cbg"><img src="http://ossweb-img.qq.com/images/nba2k/act/a20140910player/portrait/'+this.selectArr[i].avartarID+'.png" width="102" height="102"></a><span>'+this.selectArr[i].name+'</span></li>'; //alert(this.selectArr[i].firstPosition+" : "+this.selectArr[i].secondPosition); } jQuery("#playerlistUl").html(playerlist); if(jQuery(".condition a").length > 0){ jQuery(".mode a").eq(0).removeClass("cur"); jQuery(".mode a").eq(1).addClass("cur"); }else{ jQuery(".mode a").eq(0).addClass("cur"); jQuery(".mode a").eq(1).removeClass("cur"); } } } jQuery(document).ready(function(){ var curTeam = ''; //球队 var curQuality = ''; //品质 var curPosition = '';//位置 var curaHStar = '';//版本 var curSearchKey = ''; jQuery("#curTeam").val(''); jQuery("#curQuality").val(''); jQuery("#curPosition").val(''); jQuery("#curaHStar").val(''); jQuery("#curSearchKey").val(''); jQuery(".team li a").click(function(){ jQuery("#curTeam").val(jQuery(this).attr("rel")); getVal(); clearTarge('curTeam'); jQuery(".condition").append('<a href="#" class="cbg" rel="curTeam">'+curTeam+'</a>'); PlayClass.playerControl(curTeam,curQuality,curPosition,curaHStar,curSearchKey); }); jQuery("#qualityList li a").click(function(){ jQuery("#curQuality").val(jQuery(this).attr("rel")); getVal(); clearTarge('curQuality'); jQuery(".condition").append('<a href="#" class="cbg" rel="curQuality">'+curQuality+'</a>'); PlayClass.playerControl(curTeam,curQuality,curPosition,curaHStar,curSearchKey); }); jQuery("#searchBtn").click(function(){ jQuery("#curSearchKey").val(jQuery("#searchKey").val().trim()); getVal(); PlayClass.playerControl(curTeam,curQuality,curPosition,curaHStar,curSearchKey); }); jQuery("#positionList li a").click(function(){ jQuery("#curPosition").val(jQuery(this).attr("rel")); getVal(); clearTarge('curPosition'); jQuery(".condition").append('<a href="#" class="cbg" rel="curPosition">'+curPosition+'</a>'); PlayClass.playerControl(curTeam,curQuality,curPosition,curaHStar,curSearchKey); }); jQuery("#aHStarList li a").click(function(){ jQuery("#curaHStar").val(jQuery(this).attr("rel")); getVal(); clearTarge('curaHStar'); jQuery(".condition").append('<a href="#" class="cbg" rel="curaHStar">'+curaHStar+'</a>'); PlayClass.playerControl(curTeam,curQuality,curPosition,curaHStar,curSearchKey); }); jQuery(".condition a").live("click",function(){ jQuery("#"+jQuery(this).attr("rel")).val(''); jQuery(this).remove(); getVal(); PlayClass.playerControl(curTeam,curQuality,curPosition,curaHStar,curSearchKey); }); function getVal(){ curTeam = jQuery("#curTeam").val(); curQuality = jQuery("#curQuality").val(); curPosition = jQuery("#curPosition").val(); curaHStar = jQuery("#curaHStar").val(); curSearchKey = jQuery("#curSearchKey").val(); } function clearTarge(targe){ jQuery(".condition a").each(function(i){ if(jQuery(this).attr("rel") == targe){ jQuery(this).remove(); } }); } String.prototype.trim = function(){ return this.replace(/^\s\s*/,'').replace(/\s\s*$/,''); } PlayClass.playerControl('','','','',''); });/* |xGv00|c7269f94079dde9991105e5497927c82 */