如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
算法题一:/***请以空格作为间隔,拆分字符串’AppleOrangeBananaStrawberry’,组成数组$fruit,*数组中所有元素都用小写字母,并按照字母先后次序排序*/classsort{private$str;publicfunction__construct($str){$this->str=strtolower($str);}privatefunctionexplodes(){if(empty($this->str))returnarray();$arr=explode(”“,$this->str);returnis_array($arr)?$arr:array($arr);}publicfunctionsort(){$explode=$this->explodes();sort($explode);return$explode;}}//$str=’AppleOrangeBananaStrawberry’;////$sortob=newsort($str);////var_dump($sortob->sort());算法题二:/***对于用户输入一串字符串$string,要求$string中只能包含大于0的数字和英文逗号,*请用正则表达式验证,对于不符合要求的$string返回出错信息*/classregx{publicstaticfunctioncheck($str){if(preg_match(“/^([1-9,])+$/”,$str)){returntrue;}returnfalse;}}$str=”12345,6″;if(regx::check($str)){echo“suc”;}else{echo“fail”;}算法题三:<?php/***请写一段程序,在服务器创建一个文件fruit.dat,将试题3中得到的数组写入到改文件中,*然后写一段程序从文件中读取并还原数组*@authorzhuwenqiong**/classsort{private$str;publicfunction__construct($str){$this->str=strtolower($str);}privatefunctionexplodes(){if(empty($this->str))returnarray();$arr=explode(”“,$this->str);returnis_array($arr)?$arr:array($arr);}publicfunctionsort(){$explode=$this->explodes();sort($explode);return$explode;}}classfile{private$sort=null;private$filepath;publicfunction__construct($arrobj,$path){$this->sort=$arrobj;$this->filepath=$path;}privatefunctiongetresource($filename,$mode){returnfopen($this->filepath.$filename,$mode);}privatefunctioncloseresource($resource){fclose($resource);}publicfunctionsavefile($filename){$arr=$this->sort->sort();$fopen=$this->getresource($filename,”a+”);if(!$fopen){echo“文件打开失败!”;exit;}var_dump($arr);foreach($arras$key=>$value){fwrite($fopen,$value.”\n”);}$this->closeresource($fopen);}publicfunctionreadfile($filename){$this->savefile($filename);$fopen=$this->getresource($filename,”r”);if(!$fopen){echo“文件打开失败!”;exit;}$arr=array();while(!feof($fopen)){$get=fgets($fopen);if(!empty($get))$arr[]=str_replace(“\n”,”",$get);}