【网页制作-php】网页显示CS/DS/BA项目信息列表

cs1.txt

Stanford MSCS
https://cs.stanford.edu/admissions/checklist
ddl: 12-04
https://cs.stanford.edu/admissions/deadlines
网申链接
https://gradadmissions.stanford.edu/applying
录取数据统计
master_info/stanford_cs.html

Yale MSCS
https://cpsc.yale.edu/academics/graduate-program/master-science
ddl: 01-02
https://cpsc.yale.edu/academics/graduate-program/yale-computer-science-admissions-faq
网申链接
https://apply.grad.yale.edu/apply/status
录取数据统计
master_info/yale_cs.html
......

step1:program_info.php v01

读取txt文件,使用switch语句匹配关键字段,echo显示在网页

';
            $line2 = fgets($myfile);
            echo $line2.'
'; break; case stristr(substr($line1,0,-1),"网申链接") == True: echo $line1.'
'; $line2 = fgets($myfile); echo $line2.'
'; break; } } fclose( $myfile ); ?>

网页显示如下
image.png

step2:program_info.php v02

将每个项目的信息保存到program对象的数组中

program_info['name'] == Null){//mark the start of a master program
        $program->program_info['name'] = $line1;
        $program->program_info['link'] = $line2;
    }
    
    switch($line1){
        case stristr($line1,"ddl") == True:
            $program->program_info['ddl']=array($line1, $line2);
            break;
            
        case stristr(substr($line1,0,-1),"网申链接") == True:
            $program->program_info['网申链接']=array($line1, $line2);
            break;      
    }
}

fclose( $myfile );

?>


网页显示如下
image.png

step3:program_info.php v03

program_info['name'] == Null) continue;//跳过连续的空格
        $program_list[]=$program;   
        unset($program);
        continue;
      }
    $line2 = fgets($myfile);

    if($program->program_info['name'] == Null){//mark the start of a master program
        $program->program_info['name'] = array($line1, $line2);
    }
    
    switch($line1){
        case stristr($line1,"ddl") == True:
            $program->program_info['ddl']=array($line1, $line2);
            break;
            
        case stristr(substr($line1,0,-1),"网申链接") == True:
            $program->program_info['网申链接']=array($line1, $line2);
            break;      
    }
}

fclose( $myfile );
?>


html部分如下:



    
    
    
    
    


CS项目信息

'; foreach($program->program_info as $item){ echo ''; } echo ''; } ?>
'; echo '', $item[0], ''; echo '

网页显示如下:
image.png

添加TOEFL信息列后,由于部分项目没有TOEFL信息,导致显示出了问题,一大片空白超难看
image.png

step4:program_info.php v04

填充缺失的信息项并对数组进行排序

 foreach($program_list as $program){
    //处理缺失的信息列
    if($program->program_info['04-TOEFL']==Null) {
        $program->program_info['04-TOEFL'] = array('N/A', '#');
    }
    if($program->program_info['05-录取数据']==Null) {
        $program->program_info['05-录取数据'] = array('N/A', '#');
    }
    //对associate数组进行排序,方便统一显示
    ksort($program->program_info);

完整代码如下:

program_info['01-name'] == Null) continue;//跳过连续的空格
        $program_list[]=$program;   
        unset($program);
        continue;
      }
    $line2 = fgets($myfile);

    if($program->program_info['01-name'] == Null){//mark the start of a master program
        $program->program_info['01-name'] = array($line1, $line2);
    }
    
    switch($line1){
        case stristr($line1,"ddl") == True:
            $program->program_info['02-ddl']=array($line1, $line2);
            break;
            
        case stristr(substr($line1,0,-1),"网申链接") == True:
            $program->program_info['03-网申链接']=array($line1, $line2);
            break;      
            
        case stristr(substr($line1,0,-1),"TOEFL") == True:
            $program->program_info['04-TOEFL']=array($line1, $line2);
            break;  
            
        case stristr(substr($line1,0,-1),"录取数据") == True:
            if($program->program_info['05-录取数据'] == Null)
                $program->program_info['05-录取数据']=array($line1, $line2);
            break;
    }
}

fclose( $myfile );
?>

html显示部分:



    
    
    
    
    


CS项目信息

program_info['04-TOEFL']==Null) { $program->program_info['04-TOEFL'] = array('N/A', '#'); } if($program->program_info['05-录取数据']==Null) { $program->program_info['05-录取数据'] = array('N/A', '#'); } //对associate数组进行排序,方便统一显示 ksort($program->program_info); //开始逐行显示表格 echo ''; foreach($program->program_info as $item){ echo ''; } echo ''; } ?>
'; echo '', $item[0], ''; echo '

网页显示如下:
image.png

step5:program_info.php v05

将功能封装成函数,方便读取多个文件(CS/DS/BA/MIS),然后在网页显示多个项目的列表,每个专业一个table;另外将“录取数据”信息栏设置成用小窗口显示

program_info['01-name'] == Null) continue;//跳过连续的空格
        $program_list[]=$program;   
        unset($program);
        continue;
      }
      $line2 = fgets($myfile);

    if($program->program_info['01-name'] == Null){//mark the start of a master program
        $program->program_info['01-name'] = array($line1, $line2);
    }
    
    switch($line1){
        case stristr($line1,"ddl") == True:
        $program->program_info['02-ddl']=array(substr($line1,0,-1), substr($line2,0,-1));
        break;
        
        case stristr(substr($line1,0,-1),"网申链接") == True:
        $program->program_info['03-网申链接']=array(substr($line1,0,-1), substr($line2,0,-1));
        break;      
        
        case stristr(substr($line1,0,-1),"TOEFL") == True:
        $program->program_info['04-TOEFL']=array(substr($line1,0,-1), substr($line2,0,-1));
        break;  
        
        case stristr(substr($line1,0,-1),"录取数据") == True:
        if($program->program_info['05-录取数据'] == Null)
            $program->program_info['05-录取数据']=array(substr($line1,0,-1), substr($line2,0,-1));
        break;
    }
}
fclose( $myfile );
return $program_list;
}

//定义显示html的函数,$title是表格的标题,如:“CS项目信息”,“MIS项目信息”
function show_program_list($program_list, $title){
    echo '

'.$title.'

'; foreach($program_list as $program){ //处理缺失的信息列 if($program->program_info['04-TOEFL']==Null) { $program->program_info['04-TOEFL'] = array('N/A', '#'); } if($program->program_info['05-录取数据']==Null) { $program->program_info['05-录取数据'] = array('N/A', '#'); } //对associate数组进行排序,方便统一显示 ksort($program->program_info); //开始逐行显示表格 echo ''; foreach($program->program_info as $item){ echo ''; } echo ''; } echo '
'; if(stristr($item[0],"录取数据") == True) //if(1==0) echo ''.$item[0].''; else echo '', $item[0], ''; echo '
'; } ?>

html显示代码



    
    
    
    
    



    

需要蟹老板留学服务的,( ̄︶ ̄)↗请加小助理微信:895718791(注明:留学申请服务) 语音咨询:600元/小时(半小时起约)签约保录top 50全程服务(5万元/10所学校)

网页显示,直接戳这里=> DS/BA/CS/MIS项目信息列表
Github代码=>program_list

你可能感兴趣的:(【网页制作-php】网页显示CS/DS/BA项目信息列表)