题一:
class sort{private $str;public function __construct($str){$this->str=strtolower($str);}private function explodes(){if(empty($this->str)) return array();$arr=explode(” “,$this->str);return is_array($arr)?$arr:array($arr);}public function sort(){$explode=$this->explodes();sort($explode);return $explode;}}//$str=’Apple Orange Banana Strawberry’;////$sortob=new sort($str);////var_dump($sortob->sort());复制代码题二:
class regx{public static function check($str){if(preg_match(“/^([1-9,])+$/”,$str)){return true;}return false;}}$str=”12345,6″;if(regx::check($str)){echo “suc”;}else{echo “fail”;}复制代码题三:
<?phpclass sort{private $str;public function __construct($str){$this->str=strtolower($str);}private function explodes(){if(empty($this->str)) return array();$arr=explode(” “,$this->str);return is_array($arr)?$arr:array($arr);}public function sort(){$explode=$this->explodes();sort($explode);return $explode;}}class file{private $sort=null;private $filepath;public function __construct($arrobj,$path){$this->sort=$arrobj;$this->filepath=$path;}private function getresource($filename,$mode){return fopen($this->filepath.$filename,$mode);}private function closeresource($resource){fclose($resource);}public function savefile($filename){$arr=$this->sort->sort();$fopen=$this->getresource($filename,”a+”);if(!$fopen){echo “文件打开失败!”;exit;}var_dump($arr);foreach($arr as $key=>$value){fwrite($fopen,$value.”n”);}$this->closeresource($fopen);}public function readfile($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);}$this->closeresource($fopen);return $arr;}}$file=new file(new sort(‘Apple Orange Banana Strawberry’),”E:”);$arr=$file->readfile(“fruit.dat”);var_dump($arr);?>复制代码题四:
<?phpclass Db{private static $instance;public $handle;private function __construct($host,$username,$password,$dbname){$this->handle=NULL;$this->getcon($host,$username,$password,$dbname);}public static function getBb(){self::$instance=new Db();return self::$instance;}private function getcon($host,$username,$password,$dbname){if($this->handle!=NULL){return true;}$this->handle= mysqli_connect($host,$username,$password,$dbname);}}复制代码最后,这些都是腾讯的面试题!不难吧,可当初就是习惯了代码提示(eclipse ide),导致很多函数只是记得有,但不敢确定到底是什么功能!



